赞
踩
目录
在编程中,需要接受用户输入的数据,需要一个扫描器(对象),就是Scanner
1)导入该类的所在包,java.util.* ; import java.util.Scanner;
2)创建该类对象(声明变量);Scanner myScanner = new Scanner(System.in);
3)调用里面的功能
System.out.println("Pleas enter your name");
Srting name = myScanner.next();//接受完整字符串
System.out.println("Pleas enter your age");
Srting age = myScanner.nextInt();//接受Int型
System.out.println("Pleas enter your salry");
Srting salry = myScanner.nextDouble();//接受double型
- import java.util.Scanner;//
- public class Input{
- public static void main(String[] args){
- Scanner myScanner = new Scanner(System.in);
- System.out.println("Pleas enter your name");
- String name = myScanner.next();
-
- System.out.println("Pleas enter your age");
- int age = myScanner.nextInt();
-
- System.out.println("Pleas enter your salry");
- double salry = myScanner.nextDouble();
-
- System.out.println("Name=" + name + '\t' + "Age=" + age
- + '\t' + "Salry=" + salry+ '\t' );
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。