import java.lang.Math.* ;
class Statements{
public static void main(String[]args){
int x = 3;
String name = "Dirk";
x = x * 17;
System.out.println("x is " + x);
double d = Math.random();
while (x > 12) {
x = x-1;
System.out.print("x is " + x);
}
for (x = 0; x < 10; x = x + 1) {
System.out.println(" x is now " + x);
}
if (x == 10) {
System.out.println("x must be 10");
} else {
System.out.print("x isn`t 10");
}
if ((x < 3) & (name.equals ("Dirk"))) {
System.out.println("Gently");
}
System.out.print("this line runs no matter what");
}
}
Unable to understand the output of Bold and Underlined statement. In my opinion it must not print this line instead It should print the line that is strikethrough in the program.
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
22 October 2020, 21:44useful
Last line displayed in FOR loop is: "x is now 9". Here x = 9.
After printing this line variable x is increased to 10, x = 10. And then condition in the loop (x < 10) is checked. For it is false, loop FOR is ended.
But variable x remains 10.
+1
Dinesh
22 October 2020, 22:07
Thank you so much for your kind explanation.
0