java字符串数组的比较_Java,如何将字符串与字符串数组进行比较

我一直在这里搜索一段时间,但一直未能找到答案.

我基本上需要使用数组来完成大学的这项任务.然后我应该检查输入(也是一个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%5s\n", 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!");

}

}

}

如果以前曾经问过这个问题,我很抱歉,如果它是一个双重问题,我会将其删除.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值