Write a program that displays the following three messages on separate lines: Welcome to Java, Welcome to Computer Science, and Programming is fun
Answers
Answer:
Str1=welcome to java
Str2=welcome to computer science
Str3=program is fun
Print (str1)
Print (str2)
Print (str3)
Explanation:
import java.util.*;
public class Menu
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int ch;
String a,b,c;
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
ch =in.nextInt();
switch(ch)
{
case 1:
System.out.println("Welcome to Java");
a=in.nextString();
System.out.println("Welcome to Java="+a);
break;
case 2:
System.out.println("Welcome to Computer Science");
b=in.nextString();
System.out.println("Welcome to Computer Science="+b);
break;
case 3:
System.out.println("Programming is fun");
c=in.nextString();
System.out.println("Programming is fun="+c);
break;
default:
System.out.println("Wrong choice");
}
}
}
Explanation:
Since, the program is about to display a list various string character so we should use the switch-case format here because, in Java only switch-case is formulated to display a menu list.
We should accept separate variables as string characters to display each individual message separately.
While we should tap to each individual character taken for each individual message then that message will be appeared or if we tap them by not removing others then they will be appeared one after another in a separate line.
We can take any variable but when the variable will not match with any of the accepted variable then default message will be appeared.
For more java programmings recommended the given links, as I solved earlier_
brainly.in/question/14335606
brainly.in/question/14323927
https://brainly.in/question/14370842