Menu
Topics Index
...
`

ifelse condition and for loop


If you need explanation Read this topic

If you need Answer Take test on this topic

ifelse condition and for loop
What will be the output of the following program?
public class Loops {
    public static void main(String args[]) {
        for (int i = 1; i <= 5; i++) {
            if (i % (3 * 5) == 0)
                System.out.print("Andhra" + ",");
            else if (i % 5 == 0)
                System.out.print("Pradesh" + ",");
            else if (i % 3 == 0)
                System.out.print("India" + ",");
            else
                System.out.println(i + ",");
        }
    }
}

A. 1,2,India,4,
B. 1,2,India,4,Pradesh,
C. Andhra,1,2,India,4,Pradesh,
D. Some other output
E. Compilation Error or Runtime Error
Topic: for Loop In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer is 'D' because in else statement  println is used so cursor goes to new line

Posted by Sai Teja    2013-11-18 04:09:13


answer 'D' its just a simple loop and statement

Posted by Mani Deep    2013-11-18 04:13:25


answer is D because the output is
1,
2,
India,4,
Pradesh, as else has println which makes the cursor to go to next line..

Posted by Sunil Kumar    2013-11-19 07:58:25


Congratulations Sunil Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-11-20 03:58:25


© meritcampus 2019

All Rights Reserved.

Open In App