栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

第一周作业

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第一周作业

第一周作业
  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 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]+" ");
            }
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/349309.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号