
How to input from keyboard, both strings and characters and display the result on the screen with the easiest method in Java?

Hi Friend,
Try the following code:
import java.util.*;
public class ReadFromConsole {
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
System.out.println("Enter a Character:");
int i=System.in.read();
char ch=(char)i;
System.out.println("Enter an Integer:");
int num=input.nextInt();
System.out.println("Enter String:");
String st=input.next();
System.out.println("Character is: "+ch);
System.out.println("Number is: "+num);
System.out.println("String is: "+st);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.