[英]System.out.println is not printing output?
I am trying to have the list for palindrome but it doesn't give any kind of output. 我正在尝试列出回文清单,但没有给出任何输出。 But it works when I am checking for palindrome.
但是,当我检查回文时,它可以工作。
public class Main {
public static void main(String[] args) {
int num=0 ,org=0 , rem = 0,rev=0 ,a=0;
for(num=12 ; num<=101; num++) {
org=num ;
while(num>0) {
rem = num % 10 ;
num = num /10 ;
rev= (10*rev)+rem;
}
if(rev==org)
System.out.println(org);
}
}
}
Why am I not getting any output? 为什么我没有得到任何输出?
You have two errors : 您有两个错误:
rev
to 0 in each iteration (otherwise, rev
would only be correct in the first iteration). rev
重置为0(否则, rev
仅在第一次迭代中是正确的)。 num=org;
num=org;
at the end of each iteration, to restore the value of your loop variable. It should look like this : 它应该看起来像这样:
for(num=12 ; num<=101; num++) {
org=num ;
rev = 0; // added
while(num>0) {
rem = num % 10 ;
num = num /10 ;
rev= (10*rev)+rem;
}
if(rev==org)
System.out.println(org);
num = org; // added
}
Output : 输出:
22
33
44
55
66
77
88
99
101
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.