我一直在这里搜索一段时间,但一直未能找到答案.
我基本上需要使用数组来完成大学的这项任务.然后我应该检查输入(也是一个String)匹配String数组中存储的内容.
我知道可以通过使用.equals()方法轻松比较Strings.但是,相同的方法不适用于String数组.
我为StackOverflow创建了以下代码示例,因此您可以使用它来向我解释,如果您愿意的话.
我究竟做错了什么?
import java.util.Scanner;
class IdiocyCentral {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
/*Prints out the welcome message at the top of the screen*/
System.out.printf("%55s", "**WELCOME TO IDIOCY CENTRAL**n");
System.out.printf("%55s", "=================================n");
String [] codes = {"G22", "K13", "I30", "S20"};
System.out.printf("%5s%5s%5s%5sn", codes[0], codes[1], codes[2], codes[3]);
System.out.printf("Enter one of the above!n");
String usercode = in.nextLine();
if (codes.equals(usercode)) {
System.out.printf("What's the matter with you?n");
}
else {
System.out.printf("Youda man!");
}
}
}
如果以前曾经问过这个问题,我很抱歉,如果它是一个双重问题,我会将其删除.
本文发布于:2024-01-31 08:12:15,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170665993627024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |