+ 1
Array Forloop Why itâs print out 1882? Please Help
public class Program { public static void main(String[] args) { int p=1000; int X=2881; int[]store=new int[4]; for(int i=0;i<4;i++) { store[i]=X/p; X=X-(X/p)*p; p/=10; } for(int i=0; i<4;i++) { System.out.println(store[3-i]); } } }
3 Answers
+ 2
~ swim ~
thank you for to share your professional knowledge and your help .
X1=2881-(2881/1000)x1000
2881-2000
881
X2= 881-(881/100)x100
881-800
81
X3= 81-(81/10)x10
81-80
1
X4 = 1-(1/10)x10
1-0
1
so X= 881, 81, 1, and 1.
There is no 2 and even itâs print reverse itâs not should be
1
1
81
881
+ 2
~ swim ~ thank you Sir
now itâs make a lot of sencen for me đ
+ 1
~ swim ~ i am confused with X=X-(X/p)*p
X=2881
so it will be
2881-(2881/1000)*1000
so X= 0 ?
i know p=1000
and it will each time ivide 10 for 4 times it will be 1000,100,10,1