Example:
package javaapplication;
import java.util.Scanner;
/**
*
* @author Rathorji
*/
public class JavaApplication {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a;
float b;
String s;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
s = sc.nextLine(); //scans the data for input of string
System.out.println("You entered string " + s);
System.out.println("Enter an integer");
a = sc.nextInt(); //scans the data for input of integer
System.out.println("You entered integer " + a);
System.out.println("Enter a float");
b = sc.nextFloat(); //scans the data for input of float
System.out.println("You entered float " + b);
}
}
output:
run:
Enter a string stint You entered string stint Enter an integer 10 You entered integer 10 Enter a float 10.0 You entered float 10.0 |