//© learnjavaapi.blogspot.com
import java.util.Scanner;
class ScannerDemo{
public static void main(String args[]){
int num1;
float num2,tot;
String name;
Scanner scn=new Scanner(System.in);
System.out.print("Enter your name \t: " );
name=scn.nextLine();
System.out.print("Enter a Float value \t: " );
num2=scn.nextFloat();
System.out.print("Enter an Integer value \t: " );
num1=scn.nextInt();
tot=num1+num2;
System.out.println("Hi "+name+" total is \t: "+ tot );
}
}
Output :
In above example I have used the created Scanner object to read three different data. String,int and float. See the java documentation for more details about Scanner class.
Class : Scanner
Since : Java 1.5
Scanner








0 comments:
Post a Comment