0
2 questions about java correct errors,how to correct
a) int d=0; p=1; while (d<=5){ p*=d; ++d; b) for(int y=100; y>=1; y++); System.out.println(y);
2 odpowiedzi
+ 1
a) d is start with 0 so p*=d-->p=0 and then d became 1 but still p=0 so 0*1=0
b)the for will continue forever try changing y++ to y--, so it will print 100,99,98,97.... if you want to print 1,2,3....use for(int y=1;i<=100;y++)
0
a) int d=0, p=1;
the ; ends the current instruction, so all the compiler sees is just p=0, where p is undefined. Also, you mistyped int (you put into instead of int).
while(d<=5){
p*=d;
++d;
}
You were missing the closing brace. Now if you print p you should see its value.
b) you want y-- instead of y++, otherwise the value of i will increment indefinitely in an endless loop