java编程题判断回文数

java编程题判断回文数,第1张

Scanner in = new Scanner(Systemin);

Systemoutprintln("请输入一个整数N=:");

int input = innextInt();

int i = 0;

int sum = 0;

int record=input;

while(true){

i = input%10;

sum =sum10+i;

input /= 10;

if(input==0) break;

}

if(sum==record)Systemoutprintln("是回文");

else Systemoutprintln("不是回文");

#include

#include

void main()

{

int year,month,day;

int flog;

scanf("%d,%d",&year,&month);

flog=1;

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:day=31;break;

case 4:

case 6:

case 9:

case 11:day=30;break;

case 2: if( (year%4==0 &&(year%100)!=0)||year%400==0)

printf("this is leap year\n");

else

printf("this is not leap year\n");

break;

default :flog=0;

}

if(flog)

printf("%d",day=28);

else

printf("%d",day=29);

getch();

C语言

#include <stdioh>

bool fun(int n)

{

int m=0,v=n;

while(v>0)

{

m=m10+v%10;

v/=10;

}

return (m==n);

}

void main()

{

int i,count=0;

for(i=1234;i<=9875;i++)

if(fun(i)==true)

count++;

printf("%d\n",count);

}

首先你a在判断位数的时候已经被改掉了,接下来的读取每一位的数字的时候就会出错。

新开个变量int b = a吧。

if (b=1)永远都是返回true的 因为这是一个赋值语句

应该是if (b == 1)

初学的时候经常会犯这个错误。

建议如果判断一个变量等于一个常量的时候把常量写前面,

如 (1 == b)

这样万一你少打一个等号, 编译器会报错

以上就是关于java编程题判断回文数全部的内容,包括:java编程题判断回文数、C语言程序题函数判断回文数、判断回文数的程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10140354.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存