Blog Archive

Saturday, 19 November 2016

How to accept different types of input from user in java.

Java Program to accept different types of input from user.

import java.util.Scanner;
class AcceptInput
{

  public static void main(String []args)
 {
   int a;
   String name;
   float ft;
   Scanner sc=new Scanner(System.in);
System.out.println("Enter Integer\n");
 a=sc.nextInt();
 System.out.println("Enter String \n");
name=sc.nextLine();
System.out.println("Enter Flaot value \n");
ft=sc.nextFloat();
System.out.println("Integer Value is:" +a);
System.out.println("String Value is:" +name);
System.out.println("Float value Is" +ft);
 }
}

No comments:

Post a Comment