因此,我正在为CSCI课程做这项任务,我无法将自己的大脑包围在浩然之中,做它需要我做的事情。继承人的任务是什么的一部分,说:“提示用户佩斯颜色/香料,然后将它们存储在一个阵列或阵列状结构免除以相反的顺序的颜色/口味。” 而我的继承人代码:以相反的顺序打印一组单词
import java.util.Scanner;
import java.util.Arrays;
public class PezDispenser {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String col1;
String col2;
String col3;
String col4;
String col5;
String col6;
String col7;
String col8;
String col9;
String col10;
System.out.println("I need ten colors or favors");
col1 = input.nextInt();
col2 = input.nextInt();
col3 = input.nextInt();
col4 = input.nextInt();
col5 = input.nextInt();
col6 = input.nextInt();
col7 = input.nextInt();
col8 = input.nextInt();
col9 = input.nextInt();
col10 = input.nextInt();
String[] myArray = new String[] {col1 + col2 + col3 + col4 + col5 + col6 + col7 + col8 + col9 + col10};
System.out.println("Now to dispense");
System.out.println(myArray.asList.reverse(myArray));
}
}
问题是,这只适用于数字,键入一个字母在程序崩溃。
你需要'nextLine()'或'next()'作为'Strings' –