Consider the following Java program :
public static void main (string args [ ])
{
int result, x ;
x = 1 ;
result = 0;
while (x < = 10) {
if (x%2 == 0) result + = x ;
+ + x ;
}
System.out.println(result) ;
}
}
Which of the following will be the output of the above program?
A. 35 B. 30 C. 45 D. 35
2.
public static void main(String args[])
{
int i = 1;
System.out.println(i+” , “);
System.out.println(i);
}
public int m(int i)
{
i += 2;
return i;
}
}
A.3,1 B 1,1 C 1,3
Question 1: // TestCode.java public class TestCode { public static void main (String args [ ]) { int result, x ; x = 1 ; result = 0; while (x <= 10) { if (x%2 == 0) result += x ; ++x ; } System.out.println(result) ; } } Output of the given code is 30 Answer: B. 30 Question 2: // TestCode.java public class TestCode { public static void main(String args[]) { int i = 1; System.out.println(i+" , "); System.out.println(i); } public int m(int i) { i += 2; return i; } } Output of the given code is 1 , 1 Answer: B 1,1
Get Answers For Free
Most questions answered within 1 hours.