Q.- Given:-
public static void main(String [ ] args) {
int sum = 0;
int xVal;
for( xVal=1 ; xVal <= 5 ; xVal++)
{
sum = sum + xVal ;
}
System.out.print("The sum of " + xVal + " numbers is : "+sum);
}
What is the result ?
A) The sum of 5 numbers is : 15
B) The sum of 5 numbers is : 10
C) The sum of 4 numbers is : 10
D) A compile time error occurs.
E) None of these
⧪ please give your answer in a comment section.
public static void main(String [ ] args) {
int sum = 0;
int xVal;
for( xVal=1 ; xVal <= 5 ; xVal++)
{
sum = sum + xVal ;
}
System.out.print("The sum of " + xVal + " numbers is : "+sum);
}
What is the result ?
A) The sum of 5 numbers is : 15
B) The sum of 5 numbers is : 10
C) The sum of 4 numbers is : 10
D) A compile time error occurs.
E) None of these
⧪ please give your answer in a comment section.
5 Comments
Option A
ReplyDeleteA
ReplyDeleteNone
ReplyDeleteAnswer is The sum of 6 numbers is : 15
E
ReplyDeleteE
ReplyDeleteAnswer is The sum of 6 numbers is : 15