Java Eclipse: How to accept input from User / Print User Input

In this program we gonna get String, Int and Float values from user and displays in console of IDE.


Program:

import java.util.Scanner; //Library to use scanning

public class DataFromUser { //Default Class
public static void main(String[] args) { //Main Function
Scanner in = new Scanner(System.in); //defining In to scan

System.out.println("Enter string, Integer, Float wanted to Print");

//getting datas from user
     String s = in.nextLine();
     int a = in.nextInt();
     float b = in.nextFloat();
   
     //printing received data
     System.out.println("You entered string  : "+s);
     System.out.println("You entered integer : "+a);   
     System.out.println("You entered float : "+b);
}
}

Output: 

Enter string, Integer, Float wanted to Print
Udaya
123
1.502
You entered string : Udaya
You entered integer : 123
You entered float : 1.502




0 comments:

Post a Comment