• 7.3作业


    1.

    package com.day05;
    import java.util.*;
    public class Demo1 {
        static Scanner sc = new Scanner(System.in);
        public static void main(String[] args) {
            int[] nums = new int[]{8,4,2,1,23,344,12};
            int sum = 0;
            boolean ak = false;
            System.out.println("请猜第一个数字:");
            int guess = sc.nextInt();
            for(int num : nums){
                if(num==guess){
                    ak = true;
                    break;
                }
            }
            System.out.println("数列依次是:");
            for (int num : nums) {
                sum += num;
                System.out.print(num+"	");
            }
            System.out.println();
            System.out.println("数列之和是:"+sum);
    
            if(ak){
                System.out.println("你猜到了有数字"+guess);
            }else{
                System.out.println("你没猜到");
            }
        }
    }

    2.

    package com.day05;
    import java.util.*;
    public class Demo2 {
        static Scanner sc = new Scanner(System.in);
        public static void main(String[] args) {
            int[] scores = new int[6];
            scores[0]=99;
            scores[1]=92;
            scores[2]=85;
            scores[3]=63;
            scores[4]=60;
            System.out.println("请输入插入的成绩:");
            int newScore = sc.nextInt();
            int index = -1;
            for (int i = 0; i < scores.length; i++) {
                if(newScore>scores[i]){
                    index = i;
                    break;
                }
            }
            System.out.println("应该放入的下标是:"+index);
            for (int i = scores.length - 2; i >= index; i--) {
                scores[i+1]=scores[i];
            }
            scores[index] = newScore;
            for (int i : scores) {
                System.out.println(i);
            }
        }
    }

    3.

    package com.day05;
    import java.util.*;
    public class Demo3 {
        static Scanner sr= new Scanner(System.in);
        public static void main(String[] args) {
            System.out.println("请输入四家店的价格");
            int price [] = new int[4];
            for(int i = 0;i<price.length;i++){
                System.out.println("第"+(i+1)+"家店的价格是:");
                price[i] = sr.nextInt();
            }
            int min=price[0];
            for(int i = 0;i<price.length;i++){
                if(min>price[i]){
                    min=price[i];
                }
            }
            System.out.println("最低价格是:"+min);
        }
    }

    4.

    package com.day05;
    import java.util.*;
    public class Demo4 {
        static Scanner sr= new Scanner(System.in);
    
        public static void main(String[] args) {
            System.out.println("请输入一个整数(输入0时程序结束):");
            int mun = sr.nextInt();
            int max =mun;
            int min =mun;
            while(mun!=0){
                System.out.println("请输入一个整数(输入0时程序结束):");
                mun = sr.nextInt();
                if(mun==0){
                    break;
                }
                if(mun<min){
                    min = mun;
                }
                if(mun>max){
                    max = mun;
                }
        }
            System.out.println("最小值为:"+min+"	"+"最大值为:"+max);
        }
    }

  • 相关阅读:
    C语言volatile
    2017-10-12 下一步计划
    关于步进电机的半流设置、衰减设置
    压力校准仪开发-----步进电机驱动
    kei中实现在线仿真看波形
    42步进电机与57步进电机
    网上的说TB6560存在的问题
    TB6560步进电机驱动板
    继承
    iOS设计模式——单例模式
  • 原文地址:https://www.cnblogs.com/zhangbupang/p/11135304.html
Copyright © 2020-2023  润新知