java program to accept user input

Solutions on MaxInterview for java program to accept user input by the best coders in the world

showing results for - "java program to accept user input"
Bianca
24 Sep 2016
1import java.util.Scanner;
2
3class GetInputData
4{
5  public static void main(String args[])
6  {
7     int num;
8     float fnum;
9     String str;
10 
11     Scanner in = new Scanner(System.in);
12 
13     //Get input String
14     System.out.println("Enter a string: ");
15     str = in.nextLine();
16     System.out.println("Input String is: "+str);
17 
18     //Get input Integer
19     System.out.println("Enter an integer: ");
20     num = in.nextInt();
21     System.out.println("Input Integer is: "+num);
22 
23     //Get input float number
24     System.out.println("Enter a float number: ");
25     fnum = in.nextFloat();
26     System.out.println("Input Float number is: "+fnum); 
27  }
28}