ArrayList str=new ArrayList();
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
str.add(scanner.next());
}
System.out.println(1);
我想问什么情况下这里的“输出1”这条语句才会执行?
还有就是我想键盘输入5行,每行不一定多少个元素,5行之后执行“输出1”这条语句,应该怎么写?
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
str.add(scanner.next());
}
System.out.println(1);
我想问什么情况下这里的“输出1”这条语句才会执行?
还有就是我想键盘输入5行,每行不一定多少个元素,5行之后执行“输出1”这条语句,应该怎么写?
ArrayList str = new ArrayList();
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String next = scanner.next();
if ("quit".equals(next)) {
break;
}
if ((str.size()+1)%5==0) {
System.out.println(1);
}
str.add(next);
}
}
import java.util.Scanner;public class Test {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
Scanner sn = new Scanner(System.in);
int cont = 0;
while(sn.hasNext()) {
String next = (String)sn.next();
al.add(next);
cont ++;
if(cont == 5) {
System.out.println(1);
}
if(next.equals("exit")) {
return;
}
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList str=new ArrayList();
int cont = 0;
while (scanner.hasNextLine()){
String con = scanner.nextLine();
str.addAll(Arrays.asList(con.replaceAll("\\\\s*"," ").split(" ")));
cont ++;
if(cont == 5) {
break;
}
}
System.out.println(1);
scanner.close();
}
public static void main(String[] args) {
ArrayList array = new ArrayList();
for(int x=0;x<5;x++){
Scanner sc = new Scanner(System.in);
String line =sc.nextLine();
array.add(line);
}
System.out.println(array);
}