Knowee
Questions
Features
Study Tools

Select the correct answerWhat is the valid data type for variable “p” to print “Good Morning”?switch(p){ System.out.println("Good Morning");}Optionsint and floatchar and longbyte and charbyte and short

Question

Select the correct answerWhat is the valid data type for variable “p” to print “Good Morning”?switch(p){ System.out.println("Good Morning");}Optionsint and floatchar and longbyte and charbyte and short

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is "char and long". In a switch statement in Java, the variable used in switch can be an int, char, byte, short, or enum. However, long and float are not allowed. Therefore, the variable "p" can be a char or long to print "Good Morning".

Similar Questions

the correct answerWhat is the valid data type for variable “p” to print “Good Morning”?switch(p){ System.out.println("Good Morning");}

switch(a){    default:        System.out.println("Welcome");}Of which data types can the variable ‘a’ be?1. long2. byte3. int4. char5. float6. short

Select the correct answerWhat will be the output of the following Java code? class Codetantra {    public static void main(String args[]) {         try {             System.out.print("Good" + " " + 1 / 0);          }         finally {        System.out.print("Morning");                }     } }OptionsGoodCompilation ErrorFirst "Morning" then "Exception"Morning

Select the correct answerWhat will be the output of the following Java program?class conditional_statements {    public static void main(String args[])     {         final int u=10,v=20;     while(u<v)     {      System.out.println("Good");     }     System.out.println("Morning");     } }OptionsGoodGood Morningcompile time errorrun time error

Select the correct answerWhat will be the output of the following Java code? class codetantra  {    public static void main(String args[])     {      char a = 'A';      char b = 76;      b++;      a++;      System.out.println(a + " " + b);    }   }OptionsC NB MD OA M

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.