吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1572|回复: 5
收起左侧

[Java 转载] Java语言基础知识之习题二

[复制链接]
QingYi. 发表于 2021-3-26 21:02
题目见图片附件
Seven:
[Java] 纯文本查看 复制代码
import java.util.Scanner;

public class Seven {
    static int user1, user2;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请玩家1输入石头、剪刀或者布:");
        String a = sc.nextLine();
        System.out.println("请玩家2输入石头、剪刀或者布:");
        String b = sc.nextLine();
        user1 = exchange(a, user1);
        user2 = exchange(b, user2);
        check(user1, user2);
    }

    private static void check(int user1, int user2) {
        if (user1 == user2) {
            System.out.println("平局");
            return;
        }
        if (user1 == 0) {
            if (user2 == 2) {
                System.out.println("玩家1Win");
            } else {
                System.out.println("玩家2Win");
            }
        } else if (user1 == 2) {
            if (user2 == 0) {
                System.out.println("玩家2Win");
            } else {
                System.out.println("玩家1Win");
            }
        } else if (user1 == 5) {
            System.out.println("玩家2Win");
        } else {
            System.out.println("玩家1Win");
        }
    }

    private static int exchange(String x, int n) {
        if ("剪刀".equals(x)) {
            n = 2;
        } else if ("石头".equals(x)) {
            n = 0;
        } else {
            n = 5;
        }
        return n;
    }
}


Eight:
[Asm] 纯文本查看 复制代码
public class Corporation {
    double salary;
    int hour;

    public Corporation(double salary, int hour) {
        this.salary = salary;
        this.hour = hour;
    }

    void getMoney() {
        if (this.salary < 8.0 || this.hour > 60) {
            System.out.println("Declined to 996");
            return;
        }
        double m = this.hour * this.salary;
        if (this.hour <= 40) {
            System.out.println(m);
        } else {
            System.out.println(m + (this.hour - 40 * 1.5));
        }
    }
}

public class Main {
    public static void main(String[] args) {
        Corporation user1 = new Corporation(7.50,35);
        Corporation user2 = new Corporation(8.20,47);
        Corporation user3 = new Corporation(10.00,73);
        user1.getMoney();
        user2.getMoney();
        user3.getMoney();
    }
}


Nine:
[Java] 纯文本查看 复制代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Nine {
    public static void main(String[] args) throws IOException {
        System.out.println("请输入个数及其差值");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int cnt = Integer.parseInt(s[0]);
        int dif = Integer.parseInt(s[1]);
        System.out.println("输入" + cnt +"个整数");
        String[] s1 = br.readLine().split(" ");
        int [] arr = new int[s1.length];
        for(int i = 0 ;i<arr.length;i++){
            arr[i] = Integer.parseInt(s1[i]);
        }
        for(int i = 0;i<arr.length-1;i++){
            if (Math.abs(arr[i] - arr[i+1]) >dif){
                System.out.println("数列从" + ++i + "个数开始中断");
                return;
            }
        }
        System.out.println("这是" + cnt + "个数组组成的连续数列,差值为" + dif );
    }
}


在新标签打开所有链接复制所有链接URL复制所有链接URL(反向)复制所有链接标题 + URL复制所有链接标题 + URL (MD)复制所有链接标题 + URL (BBS)复制所有链接标题 + URL (筛选)复制所有链接标题 + URL (设置复制格式)在新标签页打开所有图片链接在一个标签页显示所有图片链接
复选框 - 选中
复选框 - 取消
复选框 - 反选
单选框 - 选中
单选框 - 取消
特殊单选框 - 选中
图片.png

免费评分

参与人数 2吾爱币 +6 热心值 +2 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
lileitin + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

lileitin 发表于 2021-3-26 21:16
学习一下
liujieboss 发表于 2021-3-26 21:35
shuaibi_chen 发表于 2021-3-26 21:38
279986 发表于 2021-3-26 22:32
谢楼主分享,支持一下!
likoo 发表于 2021-3-26 23:36
学习学习!!!!!!!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-11 20:45

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表