扑克牌大小问题一直提示有数组越界非法访问等问题,求问为什么?

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] str1,str2;
        String[] tmp = str.split("-");
        if (tmp.length < 2) {
            System.out.println("ERROR");
            return;
        }
        str1 = tmp[0].split(" ");
        str2 = tmp[1].split(" ");
        HashMap<String, Integer> map = new HashMap<>();
        map.put("3", 3);
        map.put("4", 4);
        map.put("5", 5);
        map.put("6", 6);
        map.put("7", 7);
        map.put("8", 8);
        map.put("9", 9);
        map.put("10", 10);
        map.put("J", 11);
        map.put("Q", 12);
        map.put("K", 13);
        map.put("A", 14);
        map.put("2", 15);
        map.put("joker", 16);
        map.put("JOKER", 17);

        if ( isJokerBomb(str1)||isJokerBomb(str2) ) {
            System.out.println("joker JOKER");
        }else if( isBomb(str1) && !isBomb(str2) ){
            System.out.println(tmp[0]);
        }else if( !isBomb(str1) && isBomb(str2) ) {
            System.out.println(tmp[1]);
        }else if ( str1.length == str2.length ) {
            if (map.containsKey(str1[0]) && map.containsKey(str2[0])){
                System.out.println( map.get(str1[0]) > map.get(str2[0]) ? tmp[0]:tmp[1] );
            }
        }else {
            System.out.println("ERROR");
        }

    }
    static boolean isBomb(String[] str){
        return str.length == 4;
    }
    static boolean isJokerBomb(String[] str){
        return str.length == 2 && (str[0].equals("joker") && str[1].equals("JOKER")) || (str[1].equals("joker") && str[0].equals("JOKER"));
    }

}


#笔试题目#
全部评论
str.length == 2 && (str[0].equals("joker") && str[1].equals("JOKER")) || str.length == 2 && (str[1].equals("joker") && str[0].equals("JOKER")); || 后面也要判断str.length == 2
点赞 回复 分享
发布于 2022-08-08 19:22
python也是
点赞 回复 分享
发布于 2020-04-14 17:27

相关推荐

认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
05-20 21:57
已编辑
门头沟学院 Java
喜欢吃卤蛋的悲伤蛙在提需求:建信融通没消息吧,我2说有实习挂简历不理了
点赞 评论 收藏
分享
06-04 18:37
门头沟学院 Java
勇敢的ssr求对象:前面看的有点奔溃,看到只有你是真玩啊,忍不住笑出了声😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务