[Java] 实验11

1. 本次实验提供了一些代码示例,对于部分题目,只需要进行代码填空即可——将 "?" 或 "// TODO" 替换成正确的代码。

2. 条件语句和循环语句(如if, for, while等)只讲紧跟着的一条语句作为它的循环体,这条语句可以是

    - 由一个 ; 分隔的简单语句

    - 由花括号括起来的复合语句


60005 排序

可以参考书中冒泡排序插入排序的相关内容。


60006 简化的插入排序

1. 测试数据

1 2 3 4 5

6

1 2 3 4 5 

5

1 2 3 4 5

0

1 2 3 4 5

1

1 2 3 4 5 

3

2. 代码

import java.util.Scanner;

public class SimplerSort {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int repeat = in.nextInt();
    while (repeat -- != 0) {
      // Input
      int[] a = new int[5];
      for (int i = 0; i < 5; ++ i)
        a[i] = in.nextInt();
      int num = in.nextInt();
      // Output
      int idx = 0;
      // Output a[idx] which is less than num
      for (idx = 0; ? && ?; ++ idx)
        ?
      // Output num
      ?
      // Output a[idx] which is NOT less than num
      for (; ?; ++ idx)
        ?
      System.out.println();
    }
    in.close();
  }
}


60007 查找指定元素


60012 加法口诀表

import java.util.Scanner;

public class Add {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int repeat = in.nextInt();
    for (int ri = 1; ri <= repeat; ++ri) {
      int n = in.nextInt();
      int[][] a = 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值