+ 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]); } } }

20th Mar 2019, 7:15 PM
Joseph Jostar
Joseph Jostar - avatar
3 Respostas
+ 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
20th Mar 2019, 9:46 PM
Joseph Jostar
Joseph Jostar - avatar
+ 2
~ swim ~ thank you Sir now it’s make a lot of sencen for me 👍
21st Mar 2019, 1:02 AM
Joseph Jostar
Joseph Jostar - avatar
+ 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
20th Mar 2019, 7:30 PM
Joseph Jostar
Joseph Jostar - avatar