zoukankan      html  css  js  c++  java
  • 7.3作业

    程序:

    package com.homework;
    import java.util.Scanner;
    public class newSuzhi {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
    int[] nums = new int[] {8,4,2,1,23,344,12};
    System.out.println("请输入要猜的数字:");
    int newNum = sc.nextInt();
    int sum = 0;
    boolean flag = false; //标记
    for(int b : nums) {
    if(b==newNum) {
    flag =true;
    break; //判断出便不再执行
    }
    }
    System.out.println("数列依次是:");
    for(int b :nums) {
    sum += b;
    System.out.print(b+" ");
    }
    System.out.println();
    System.out.println("序列之和为"+sum);
    if(flag) { //标记开始起作用
    System.out.println("你猜到了有数字"+newNum);
    }else {
    System.out.println("对不起,你么有猜到");
    }
    }
    }

    package com.homework;
    import java.util.Scanner;
    public class chaZhi {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
    int[] scores = new int[6];
    scores[0] = 99;
    scores[1] = 85;
    scores[2] = 82;
    scores[3] = 63;
    scores[4] = 60;
    System.out.print("请输入要插入的成绩:");
    int newScore = sc.nextInt();
    int def = scores.length-1;
    //寻找要插入的位置
    for(int a = 0;a <scores.length;a++) {
    if(newScore > scores[a]) {
    def = a;
    break;
    }
    }
    System.out.println("应该放入的下标是:"+def);
    //开始挪位置
    for(int b = scores.length-2;b >= def;b--) {
    scores[b+1] = scores[b];
    }
    scores[def] = newScore;
    System.out.println("插完后的顺序为:");
    for(int v : scores) {
    System.out.print(v);
    System.out.print(" ");
    }
    }
    }

     

     习题3.1

  • 相关阅读:
    从 i++ 和 ++i 说起局部变量表和操作数栈
    数据库连接情况查询相关sql语句
    db2相关语句
    BeanUtils源码详解
    Spring注解驱动开发之AOP
    Spring注解驱动开发之IOC
    正则表达式
    linux特殊符号
    linux下面如何让一个软件/命令开机自启动
    linux文件属性
  • 原文地址:https://www.cnblogs.com/lev1/p/11133627.html
Copyright © 2011-2022 走看看