scanner类的nextInt方法
·
目录
2.定义公共类,main()方法为程序执行的窗口,程序代码需在这个窗口内(大括号内)
4.使用System.out.print()方法输出提示信息
5.调用Scan.nextInt()的方法从用户输入中读取一个整数并保存在变量T中
6.最后使用使用System.out.print()的方法将读取到的结果打印下来
1.导入util包,引入Scanner类
import java.util.Scanner;
2.定义公共类,main()方法为程序执行的窗口,程序代码需在这个窗口内(大括号内)
public class scanner类的nextInt方法{
public static void main (String[] args){
}
}
3.创建Scan对象,从System.in中输入
Scanner scan = new Scanner (System.in);
4.使用System.out.print()方法输出提示信息
System.out.print("请输入你的年龄: ")
5.调用Scan.nextInt()的方法从用户输入中读取一个整数并保存在变量T中
int T = scan.nextInt ();
6.最后使用使用System.out.print()的方法将读取到的结果打印下来
System.out.print("输入的整数是: " + T );
7.使用完后,关闭Scan对象,释放空间
Scan.close();
Scanner类(模板)
import java.util.Scanner;
public class scanner类的nextInt方法 {
public static void main(String[] arge) {
// 创建Scan对象,从System.in中输入
Scanner scan =new Scanner (System.in);
// 使用System.out.print()方法输出提示信息
System.out.print("请输入你的年龄:");
//调用scan.nextInt()方法从用户输入中读取一个整数,并保存在变量T中
int T = scan.nextInt();
//最后使用System.out.println方法将读取到的整数打印下来
System.out.println("输入的年龄是:" + T);
// 使用完后,关闭Scan对象,释放资源
scan.close();
}
}
更多推荐


所有评论(0)