You are here: Home / Topics / Take Input from User through Console in Java

Take Input from User through Console in Java

Filed under: Java on 2023-08-11 19:18:43

// Input using Console Example

import java.io.*;

class ConsoleExample
{
public static void main( String args[ ] )
{
 Console cn = System.console();
 int n;
 
 System.out.print( "Enter a Number : ");
 n = Integer.parseInt( cn.readLine() );

 System.out.println( "The given number : " + n );
}
}


Output:

Enter a Number : 100
The given number : 100

About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.