reserve a nos by using % | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

reserve a nos by using %

int a=Integer.parseInt(t1.getText()); int b=0,c=0; while(a>0) { c=a%10; b=b*10+c; a=a/10; } System.out. println(b) explain what the value of b when program is executed and also every step how I get result and explain how I check my program.......... please

1st Sep 2016, 4:51 PM
Nikunj Gupta
Nikunj Gupta - avatar
1 Antwort
0
first of all, add a semicolon in printing line. Now, what u hve done is, that parseint thing is to convert string taken frm command line and convert into integer.. store that in variable 'a'..suppose a=138.. untill 'a' is >0, a(integer) is divided by 10 and remainder is stored in 'c'. at that point, b(0 initially), is mul by 10 and add with c. and 'a' is again divided by 10, new value of 'a' is stored in 'a'(only integer part). value of b after printing will be 831
1st Sep 2016, 6:10 PM
Raj Joshi
Raj Joshi - avatar