第三次过程性考核——常用实用类

第三次考核码云链接:https://gitee.com/xywymxs/16012005_weeks_kai_ning_three

课堂练习码云链接::https://gitee.com/xywymxs/16012005_weeks_kai_ning_test

7-1 字符串逆序

输入一个字符串,对该字符串进行逆序,输出逆序后的字符串。

输入格式:

输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。

输出格式:

在一行中输出逆序后的字符串。

输入样例:

Hello World!

输出样例:

!dlroW olleH
代码:

 1 import java.util.*;
 2 public class Main 
 3 {
 4     public static void main(String[] args)
 5     {
 6         Scanner reader=new Scanner(System.in);
 7         StringBuffer str =new StringBuffer(80);
 8         str.append(reader.nextLine());
 9       System.out.println(str.reverse());
10     }
11 }

运行结果:

7-2 输出数组元素

本题要求编写程序,对顺序读入的n个整数,顺次计算后项减前项之差,并按每行三个元素的格式输出结果。

输入格式:

输入的第一行给出正整数n(1<n10)。随后一行给出n个整数,其间以空格分隔。

输出格式:

顺次计算后项减前项之差,并按每行三个元素的格式输出结果。数字间空一格,行末不得有多余空格。

输入样例:

10 5 1 7 14 6 36 4 28 50 100

输出样例:

-4 6 7 -8 30 -32 24 22 50
代码

 1 import java.util.Scanner;
 2 public class Main {
 3 
 4     public static void main(String[] args) {
 5         // TODO Auto-generated method stub
 6         @SuppressWarnings("resource")
 7         Scanner reader = new Scanner(System.in);
 8         int  n = reader.nextInt();
 9         int a[] = new int[n];
10         int b[] = new int[n-1];
11         int count = 0;
12         for(int s=0; s<n; s++) {
13             a[s] = reader.nextInt();
14         }
15         for(int j=0; j<b.length; j++) {
16             b[j] = a[count+1] - a[count];
17             count++;
18         }
19         
20         int sount = 0;
21         for(int j=0; j<b.length; j++) {
22             if(j==0) {
23                 System.out.printf("%d", b[0]);
24             }
25             else if(sount == 3) {
26                 System.out.printf("\n");
27                 System.out.printf("%d", b[j]);
28                 sount = 0;
29             }
30             else {
31                 System.out.printf(" %d", b[j]);
32             }
33             sount++;
34         }
35     }
36     
37 }

 运行结果:

7-3 选择法排序 (15 分)

本题要求将给定的n个整数从大到小排序后输出。

输入格式:

输入第一行给出一个不超过10的正整数n。第二行给出n个整数,其间以空格分隔。

输出格式:

在一行中输出从大到小有序的数列,相邻数字间有一个空格,行末不得有多余空格。

输入样例:

4 5 1 7 6

输出样例:

7 6 5 1

代码:

 1 import java.util.*;
 2 public class Main 
 3 {
 4     public static void main(String[] args) {
 5         Scanner reader = new Scanner(System.in);
 6         int n = reader.nextInt();
 7         int b[] = new int[n];
 8         for (int s = 0; s < n; s++) {
 9             b[s] = reader.nextInt();
10         }
11         for (int f = 0; f < b.length; f++) {
12             for (int j = 0; j < b.length - f - 1; j++) {
13                 if (b[j] < b[j + 1]) {
14                     int g = b[j];
15                     b[j] = b[j + 1];
16                     b[j + 1] = g;
17                 }
18             }
19         }
20         System.out.print(b[0]);
21         for (int z = 1; z < b.length; z++) {
22             System.out.printf(" %d", b[z]);
23         }
24     }
25 
26 }

 运行结果:

学习内容 代码行数 博客字数
数组练习 137行 -----
常用实用类 232行 -----
第三次考核 74行 650字
posted on 2018-11-03 20:00  相遇唯有梦相随  阅读(230)  评论(0编辑  收藏  举报