zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java刷题面试系列习题(二十)

JAVA面试 系列 刷题 习题 二十
2023-09-14 09:14:30 时间

🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈 🌈
 
🍂个人博客首页: KJ.JK
 
💖系列专栏:Java刷题面试系列

⭕题目一: 牛牛的一周


在这里插入图片描述


🌟代码演示

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        String[] arr={"Mon","Tues","Wednes","Thurs","Fri","Satur","Sun"};
        System.out.printf("%sday",arr[x-1]);
    }
}



💯思路解析

       本题目思路是:"按照题目来即可"

⭕题目二: HTTP状态码


在这里插入图片描述


🌟代码演示

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        Map<Integer,String> type=new HashMap<>();
        type.put(200,"OK");
        type.put(202,"Accepted");
        type.put(400,"Bad Request");
        type.put(403,"Forbidden");
        type.put(404,"Not Found");
        type.put(500,"Internal Server Error");
        type.put(502,"Bad Gateway");
        while(sc.hasNextInt())
            System.out.println(type.get(sc.nextInt()));
    }
}


💯思路解析

          本题目思路是:"使用map存,然后按照key来取值即可"

⭕题目三: 计算单位阶跃函数


在这里插入图片描述


🌟代码演示

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextFloat()){
            float t=sc.nextFloat();
            if(t>0) System.out.println(1);
            else if(t==0) System.out.println(0.5);
            else System.out.println(0);
        }
    }
}   

💯思路解析

       本题目思路是:"按照题目来即可"

⭕题目四: 三角形判断


在这里插入图片描述


🌟代码演示

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if (a + b > c && a + c > b && b + c > a) {
                if (a == b && b == c) {
                    System.out.println("Equilateral triangle!");
                } else if (a == b || a == c || b == c) {
                    System.out.println("Isosceles triangle!");
                } else {
                    System.out.println("Ordinary triangle!");
                }
            } else {
                System.out.println("Not a triangle!");
            }
        }
    }

}



💯思路解析

       本题目思路是:"直接按照题目来即可"

⭕题目五: 牛牛的计划


在这里插入图片描述


🌟代码演示

import java.util.*;
public class Main {
    public static void main(String[] args)
    {
        int y=0,m=0,d=0;
        int y1=0,m1=0,d1=0;
        Scanner in=new Scanner(System.in);
        //输入数据
        y=in.nextInt();m=in.nextInt();d=in.nextInt();
        y1=in.nextInt();m1=in.nextInt();d1=in.nextInt();
        String result;
        //一共3种情况:年月相同时比较天,年相同时比较月,或者直接比较年
        if((y1==y&&m==m1&&d1>=d)||(y1==y&&m1>=m)||(y1>=y))
        {
            result="yes";
        }
        else{
            result="no";
        }
        //输出结果
        System.out.println(result);
    }
}



💯思路解析

       本题目思路是:"按照题目来就行"

作者:KJ.JK

文章对你有所帮助的话,欢迎给个赞或者 star,你的支持是对作者最大的鼓励,不足之处可以在评论区多多指正,交流学习