public int quersumme(int x){
int count=0;
while(x>=1)
{
count=count+x%10;
x=x/10;
if(x%10 == -0){
int i = -0;
count= i +count;
}
}
return count;
}
Meine Frage wie kann man hier einen negativen Wert abspeichern und returnen wenn int x ein minus davor hat?
Beispiel:
int count=0;
while(x>=1)
{
count=count+x%10;
x=x/10;
if(x%10 == -0){
int i = -0;
count= i +count;
}
}
return count;
}
Meine Frage wie kann man hier einen negativen Wert abspeichern und returnen wenn int x ein minus davor hat?
Beispiel:
System.out.println(quersumme(-11)); | -2 Erwartet | 0 kommt raus |
Zuletzt bearbeitet: