User Input

Write a program in java to take string , integer and float value as input from the user and display it on the screen

import java.util.Scanner;

class GetInputData

{

  public static void main(String args[])

  {

     int num;

     float fnum;

     String str;

      Scanner in = new Scanner(System.in);

      //Get input String

     System.out.println("Enter a string: ");

     str = in.nextLine();

     System.out.println("Input String is: "+str);

      //Get input Integer

     System.out.println("Enter an integer: ");

     num = in.nextInt();

     System.out.println("Input Integer is: "+num);

      //Get input float number

     System.out.println("Enter a float number: ");

     fnum = in.nextFloat();

     System.out.println("Input Float number is: "+fnum);

  }

}

Output

Leave Comment

Important Topics

Title
Run and Compile
Hello World Program
User Input
Add Numbers
Sum of Two Numbers
Even Numbers
Odd numbers from 1 to n or 1 to 100
Even or Odd number
Average of 3 numbers
Fibonacci Series using loops
Generate random number
Largest of three Numbers
Decimal to octal conversion
Quotient and Remainder
Simple Interest
Compound Interest