Menu
Question Index
...

What will be the output of the following program?

import java.util.Random;
public class Rhymes {
    private static Random rnd = new Random();
    public static void main(String[] args) {
        StringBuffer word = null;
        switch (rnd.nextInt(2)) {
            case 1 :
                word = new StringBuffer('P');
            case 2 :
                word = new StringBuffer('G');
            default :
                word = new StringBuffer('M');
        }
        word.append('a');
        word.append('i');
        word.append('n');
        System.out.println(word);
    }
}


Pain
Gain
Main
Some other output
Output can not determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Random Class - java.util.Random Package

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App