public class TestTransform2 { public static void main(String[] args) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = null; try { s = br.readLine(); while (s != null) { if (s.equalsIgnoreCase("end")) break; System.out.println(s); s = br.readLine(); } br.close(); } catch (IOException e) { e.printStackTrace(); } } }
学习了,呵呵 /*public static void main(String[] args){ while(true) { Scanner s =new Scanner(System.in); System.out.println(s.nextLine()); if(s.nextLine().equals("exit")) { break; } } }*/ public static void main(String[] args) { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = null; try { s = br.readLine(); while (s != null) { if (s.equalsIgnoreCase("end")) break; System.out.println(s); s = br.readLine(); } br.close(); } catch (IOException e) { e.printStackTrace(); } }
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); String[] num = s.split(" "); int[] lastNum = new int[num.length]; for(int i=0;i<num.length;i++){ int x = Integer.parseInt(num[i]); lastNum[i] = x; } for(int l :lastNum){ System.out.println("Your enter num is:" + l); }
import java.util.Scanner;/** * 测试从键盘读取用户的输入,关键类为Scanner * @author Administrator * */ public class TestInput{ public static void main(String args[]){ Scanner s = new Scanner(System.in); System.out.println("请输入你的姓名:"); String name = s.nextLine(); System.out.println("请输入你的年龄:"); int age = s.nextInt(); System.out.println("请输入你的工资:"); float salary = s.nextFloat(); System.out.println("你的信息如下:"); System.out.println("姓名:"+name+"\n"+"年龄:"+age+"\n"+"工资:"+salary);
{
Scanner s =new Scanner(System.in);
System.out.println(s.nextLine());
if(s.nextLine().equals("exit"))
{
break;
}
}
{
Scanner s =new Scanner(System.in);
System.out.println(s.nextLine());
if(s.nextLine().equals("exit"))
{
break;
}
}
public class TestTransform2 {
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr); String s = null;
try {
s = br.readLine();
while (s != null) {
if (s.equalsIgnoreCase("end"))
break;
System.out.println(s);
s = br.readLine();
}
br.close(); } catch (IOException e) {
e.printStackTrace();
}
}
}
/*public static void main(String[] args){
while(true)
{
Scanner s =new Scanner(System.in);
System.out.println(s.nextLine());
if(s.nextLine().equals("exit"))
{
break;
}
}
}*/
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr); String s = null;
try {
s = br.readLine();
while (s != null) {
if (s.equalsIgnoreCase("end"))
break;
System.out.println(s);
s = br.readLine();
}
br.close(); } catch (IOException e) {
e.printStackTrace();
}
}
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String s = in.nextLine();
String[] num = s.split(" ");
int[] lastNum = new int[num.length];
for(int i=0;i<num.length;i++){
int x = Integer.parseInt(num[i]);
lastNum[i] = x;
}
for(int l :lastNum){
System.out.println("Your enter num is:" + l);
}
}
}在shell中输入的数之间要用 空格 分开
...
}也可用args数组来读取
String str=scanner.next();
for(int i=0;i<str.length();i++){
str.charAt(i);
}
public static void main(String args[]){
Scanner s = new Scanner(System.in); System.out.println("请输入你的姓名:");
String name = s.nextLine(); System.out.println("请输入你的年龄:"); int age = s.nextInt(); System.out.println("请输入你的工资:"); float salary = s.nextFloat(); System.out.println("你的信息如下:"); System.out.println("姓名:"+name+"\n"+"年龄:"+age+"\n"+"工资:"+salary);
}
}