Home > Back-end >  Eclipse run pta submit correct 0 which is wrong???????
Eclipse run pta submit correct 0 which is wrong???????

Time:04-14

Package demo2;
import java.util.Scanner;
Import the Java. Lang. Math;
/*
Enter an integer, the output is the sum of digits [
*/
Public class test1 {

Public static void main (String [] args) {
//TODO Auto - generated method stub
Int x=0, y=0, sum=0;
Scanner scanner=new Scanner(System.in);

X=scanner. NextInt ();

While (x!=0) {
If (x> 0 {
The sum + 10=x %;
X=x/10;
}

The else {
Y=(Math. Abs (x));
The sum + 10=y %;
Y=y/10;
x=y;
}
}
System. The out. Println (sum);
}

}




CodePudding user response:

  • Related