Java Program to Print the given Message

Get a Message from user and display the same.

Sample Input 1:

hello world

Sample Output 1:

hello world

Sample Input 2:

hi boss

Sample Output 2:

hi boss

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
import java.util.*;
class Message
{
 
     public static void main(String args[])
     {
 
	    String Input;
	    Scanner sc=new Scanner(System.in);
	
	    System.out.println("Get a Message from user and display the same.");
	
	    System.out.println("Enter The Input:");
	    Input=sc.nextLine();
	    System.out.println(Input);
      }

}
			
				
			

Output

Java Program to Print the given Message Output

Program Explanation

The Scanner class, which is part of the java.util package, is used to get user input. To use the Scanner class, create an object of the class and call any of the methods listed in the documentation for the Scanner class. The nextLine() method, which is used to read Strings, are used in our example.

The Input is stored in the variable Input and printed in console using println() function which is the part of System.out package.


Comments