Menu
Topics Index
...
`

Command Line1894


If you need explanation Read this topic

If you need Answer Take test on this topic

Command Line1894
What will be the output of the following program? Assume that the argument passed as - Cow Boy I Am.
public class YouGradeIs {
    public static void main(String args[]) {
        char grade = args[3].charAt(0);
        switch (grade) {
            case 'A' :
                System.out.println("Excellent!");
                break;
            case 'B' :
            case 'C' :
                System.out.println("Well done");
                break;
            case 'D' :
                System.out.println("You passed");
            case 'F' :
                System.out.println("Better try again");
                break;
            default :
                System.out.println("Invalid grade");
        }
        System.out.print("Your grade is " + grade);
    }
}

A. Excellent!
Your grade is A
B. Invalid grade
Your grade is I
C. Well done
Your grade is B
D. Some other output
E. Compilation Error or Runtime Error
Topic: Command Line Arguments In Core Java Programming

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.

Ans is A.....here args[3] is Am & args[3].chatAt(0) is A...therefore in switch case first SOP stmt gets printed...i.e.,"Excellent!"..after coming out of the switch case...another SOP stmt " your grade is A"gets printed.

Posted by Sneha Rapool    2013-11-01 04:52:55


Ans is E.. because wt are the parameters to pass in main function are nt given.. so args[] contains null value.. it leads to exception..

Posted by Om Prakash Om    2013-11-01 05:04:08


answer is B args[3] will be "I"

Posted by Shiva Goud    2013-11-01 05:07:10


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

Posted by Merit Campus    2013-11-04 12:55:31


© meritcampus 2019

All Rights Reserved.

Open In App