String input = new Scanner(System.in).next();
int input = new Scanner(System.in).nextInt();
src运行后,会有一个out,出现,这时候
out.里写
// String 变量=new Scanner(System.in).next();
//int 变量=new Scanner(System.in).nexrint();
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
System.out.print("请输入用户初始分数:");
int score=new Scanner(System.in).nextInt();
//int score=53;
int count=0;
System.out.println("加分前的成绩:"+score);
while (score<60){
score++;
count++;
}
System.out.println("加分后的成绩:"+score);
System.out.println("共加了"+count+"次!");
}
}
接收用户输入的信息
String 变量 = new Scanner(System.in).next();
或
int 变量 = new Scanner(System.in).nextInt();
使用Scanner工具类接收用户输入的信息
固定格式为:
String 变量 = new Scanner(System.in).next();
或者
int 变量 = new Scanner(System.in).nextInt();
Scanner输入:
输出的时候:
System.out.print()
System.out.println()
ln就是换行的意思了
String 变量 = new Scanner(System.in).next();
int 变量 = new Scanner(System.in).nextInt();
public class Demo { public static void main(String[] args) { } }
使用Scanner工具类接收用户输入的信息
String 变量 = new Scanner(System.in).next()
int 变量 = new Scanner(System.in).nextInt()
接受用户端输入的信息(固定的格式)
接受用户端输入的信息(固定的格式)
使用Scanner 工具类接收用户输入的信息
固定格式为:
String 变量 = new Scanner(System.in).next();
int 变量 = new Scanner(System.in).nextInt();
System.out.print();// 不用文本换行输出;
int a= new Scanner( system.in ).nextln( );
println //自动换行
print //不换行
输入数据使用scanner工具类型
System.out.print("用户输入的初始分数是:"+score) //去掉println的ln就可以实现数据的不换行操作
String 变量=new Scanner(System.in).next(); int 变量=new Scanner(System.in).nextInt();
Scanner输入工具包
固定格式: new Scanner(System.in).next();
使用Scanner工具类接收用户输入的信息固定格式:
String 变量 = new Scanner(System.in).next();
或
int 变量 = new Scanner(System.in).nextInt();
java 用户输入的代码块
变量类型 变量 等于 new Scanner(System.in).ncxtint();
如图
使用Scanner工具类接收用户输入的信息固定格式:String 变量 = new Scanner(System.in).next();或int 变量 = new Scanner(System.in).nextInt();
println打印换行,print直接打印
使用Scanner工具类接受用户输入的信息
固定格式:
String 变量名 = new Scanner(System.in).next();
或者
int 变量名 = new Scanner(System.in).nextInt();
package com.imooc; import java.util.Scanner; public class Demo01 { public static void main(String[] args) { System.out.print("请输入用户初始分数:"); int score=new Scanner(System.in).nextInt(); int count=0; System.out.println("加分前成绩"+score); while(score<60){ score++; count++; } System.out.println("加分后成绩"+score); System.out.println("共加了"+count+"次!"); } }
package com.imooc; import java.util.Scanner; public class Demo01 { public static void main(String[] args) { System.out.print("请输入用户初始分数:"); int score=new Scanner(System.in).nextInt(); int count=0; System.out.println("加分前成绩"+score); while(score<60){ score++; count++; } System.out.println("加分后成绩"+score); System.out.println("共加了"+count+"次!"); } }
package com.imooc;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) {
System.out.print("请输入用户初始分数:");
int score=new Scanner(System.in).nextInt();
int count=0;
System.out.println("加分前成绩"+score);
while(score<60){
score++;
count++;
}
System.out.println("加分后成绩"+score);
System.out.println("共加了"+count+"次!");
}
}
package com.imooc;
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) {
System.out.print("请输入用户初始分数:");
int score=new Scanner(System.in).nextInt();
int count=0;
System.out.println("加分前成绩"+score);
while(score<60){
score++;
count++;
}
System.out.println("加分后成绩"+score);
System.out.println("共加了"+count+"次!");
}
}
package com.imooc; import java.util.Scanner; public class Demo01 { public static void main(String[] args) { System.out.print("请输入用户初始分数:"); int score=new Scanner(System.in).nextInt(); int count=0; System.out.println("加分前成绩"+score); while(score<60){ score++; count++; } System.out.println("加分后成绩"+score); System.out.println("共加了"+count+"次!"); } }
注意什么时候用换行,什么时候不用。
Scanner工具接收用户输入的信息
String 变量 = new Scanner(System.in).next();
int 变量 = new Scanner(System.in).nextInt();
String(字符串) new Scanner(System.in).next(); 用户输入
int(整数,数字)new Scanner(System.in).nextInt(); 用户输入
System.out.println() 换行 把ln删除就不会换行了