第三次过程性考核

码云
7-1 输出数组元素 (15 分)

本题要求编写程序,对顺序读入的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 Second {
 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-2 字符串逆序 (15 分)

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

输入格式:

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

输出格式:

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

输入样例:

Hello World!

输出样例:

!dlroW olleH
 1 import java.util.*;
 2 
 3 public class StringInversion {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         @SuppressWarnings("resource")
 8         Scanner reader = new Scanner(System.in);
 9         StringBuffer str = new StringBuffer(80);
10         str.append(reader.nextLine());
11         System.out.println(str.reverse());
12     }
13 
14 }

 

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

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

输入格式:

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

输出格式:

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

输入样例:

4
5 1 7 6

输出样例:

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

 

7-7 猜数字 (20 分)

一群人坐在一起,每人猜一个 100 以内的数,谁的数字最接近大家平均数的一半就赢。本题就要求你找出其中的赢家。

输入格式:

输入在第一行给出一个正整数N(104​​)。随后 N 行,每行给出一个玩家的名字(由不超过8个英文字母组成的字符串)和其猜的正整数(≤ 100)。

输出格式:

在一行中顺序输出:大家平均数的一半(只输出整数部分)、赢家的名字,其间以空格分隔。题目保证赢家是唯一的。

输入样例:

7
Bob 35
Amy 28
James 98
Alice 11
Jack 45
Smith 33
Chris 62

输出样例:

22 Amy

智商不够,不会,谢谢!!!!
学习内容代码行数博客数
java数组100200
java方法100200


 

 

 

转载于:https://www.cnblogs.com/x-alchemist/p/9900991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值