java中怎么从控制台输入,说一下详细方法,本人是新手,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/16 20:31:01
怎么输入一个数?并把这个数直接赋值给一个变量!是在控制台中直接输入

package test;
import java.util.Scanner;
class tt{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int j=0;
while(j<5)
{
System.out.println("请输入一个数字:");
int i=input.nextInt();
System.out.println("您输入的数字是:"+i);
}
}
}
如果想得到字符串就用String i=input.next();

BufferedReader read = new BufferedReader(new InputStreamReader(
System.in));
try {
String line = read.readLine();
} catch (IOException e) {
e.printStackTrace();
}

public class M {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
int a = buf.readLine();
System.out.println(buf.readLine());
}
}

自己按照自己的目的再改一下