示例输入 1:
Enter the first letter:R
Enter the second letter:A
Enter the third letter:I
Enter the fourth letter:N
Enter the fifth letter:B
Enter the sixth letter:O
Enter the seventh letter:W
示例输出 1:
RAINBOW
示例输入 2:
Enter the first letter:R
Enter the second letter:E
Enter the third letter:I
Enter the fourth letter:N
Enter the fifth letter:B
Enter the sixth letter:O
Enter the seventh letter:W
示例输出 2:
The spelling is wrong
代码:
public class spellcheck {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
String str1;
String str2 = "rainbow";
int i = 0;
String a[] = new String[7];
System.out.print("Enter the first letter:");
a[0] = scan.nextLine();
System.out.print("Enter the first letter:");
a[1] = scan.nextLine();
System.out.print("Enter the first letter:");
a[2] = scan.nextLine();
System.out.print("Enter the first letter:");
a[3] = scan.nextLine();
System.out.print("Enter the first letter:");
a[4] = scan.nextLine();
System.out.print("Enter the first letter:");
a[5] = scan.nextLine();
System.out.print("Enter the first letter:");
a[6] = scan.nextLine();
}
}
下一步应该做什么?
String tmp = "";
for(int j = 0; j < a.length; j ++)
tmp += a[j];
System.out.println(tmp);
输出 -
Enter the first letter:r
Enter the first letter:a
Enter the first letter:i
Enter the first letter:n
Enter the first letter:b
Enter the first letter:o
Enter the first letter:w
rainbow
要进行比较,您可以使用内置的字符串函数 .equals -> tmp.equals("Otherstring")
我是一名优秀的程序员,十分优秀!