第一周作业

第一周作业

  1. Java三大特性:封装,继承,多态;

  2. 定义三个参数, a,b; 交换 a,b的值:

    例如:

    ​ 输入: 1 5

    ​ 输出:a = 5 ; b = 1

 import java.util.Scanner;
 
 public class ShiYiShi {
     public static void main(String[] args) {
         int a;
         int b;
         int tmp;
         Scanner sc = new Scanner(System.in);
         a = sc.nextInt();
         b = sc.nextInt();
         tmp = a;
         a = b;
         b = tmp;
         System.out.println("a = "+a+" ; "+"b = "+b);
 
 
     }
 }
  1. 定义 一个数组; 输入10个数(x>=0&&x<=100);将这10个数分为3个等级;

    ​ 统计A,B,C等级个数; (A>=90;B>=60&&B<90;C<60)

    例如 :

    ​ 输入: 59 60 70 80 88 45 90 100 95 96

    ​ 输出: A: 4 B: 4 C:2

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

public class ShiYiShi {
    public static void main(String[] args) {
        int[] array = new int[10];
        int countA = 0;
        int countB = 0;
        int countC = 0;
        Map<Character,Integer> hashmap = new HashMap<>();
        hashmap.put('A',countA);
        hashmap.put('B',countB);
        hashmap.put('C',countC);
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 10; i++) {
            array[i] = sc.nextInt();
            if (array[i] >= 90) {
                hashmap.put('A',++countA);
            }else if (array[i] >= 60) {
                hashmap.put('B',++countB);
            } else if (array[i] < 60) {
                hashmap.put('C',++countC);
            }
        }
        System.out.println("A: "+hashmap.get('A')+" "+" B: "+hashmap.get('B')+" C: "+hashmap.get('C'));
    }
}
  1. 求1-100 的和
public class ShiYiShi {
    public static void main(String[] args) {
      int count = 0;
        for (int i = 1; i <= 100; i++) {
            count += i;
        }
        System.out.println(count);
    }
}
  1. 定义一个数组,输入 5 个数,输出大于50的数

例如:

​ 输入: 40 50 45 62 50

​ 输出: 62

import java.util.Scanner;

public class ShiYiShi {
    public static void main(String[] args) {
        int[] array = new int[5];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            array[i] = sc.nextInt();
        }
        for (int i = 0; i < 5; i++) {
            if (array[i] > 50){
                System.out.print(array[i]+" ");
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兴趣使然的小小

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值