第三次 过程性考核

第三次 过程性考核

 码云地址:https://gitee.com/ddongqi/1601211701/tree/master

7-1 输出数组元素

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

 1 import java.util.Scanner;
 2 public class Main{
 3   public static void main(String args[]){
 4         Scanner reader = new Scanner(System.in);
 5         int n = reader.nextInt();
 6         int[] a = new int[n];
 7         int i=0;
 8         int cnt=0;
 9         for(i=0;i<n;i++){
10           a[i]=reader.nextInt();
11         }
12         for (i = 0; i < n - 1; i++){
13             a[i] = a[i + 1] - a[i];
14         }
15         for (i = 0; i < n - 1; i++){
16             if (i == 0){
17                 System.out.printf("%d", a[0]);
18             }
19             else if (cnt == 3){
20                 System.out.printf("\n");
21                 System.out.printf("%d", a[i]);
22                 cnt = 0;
23             }
24             else{
25                 System.out.printf(" %d", a[i]);
26             }
27             cnt++;
28         }
29       }
30     }

  程序设计思路:定义一个数组,利用数组的属性

  知识点:数组

 

  

输入样例:

10
5 1 7 14 6 36 4 28 50 100

输出样例:

-4 6 7
-8 30 -32
24 22 50
 
7-2 字符串逆序

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

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

  程序设计思路:利用StringBuffer实现翻转

输入样例:

Hello World!

输出样例:

!dlroW olleH
7-3 选择法排序 

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

 1 import java.util.Scanner;
 2 public class Main{
 3   public static void main(String args[]){
 4     Scanner reader = new Scanner(System.in);
 5       int n = reader.nextInt();
 6       int[] a = new int[n];
 7       int x=0;
 8       for(int i=0;i<n;i++){
 9         a[i]=reader.nextInt();
10       }
11       for(int i=0;i<n;i++){
12         for(int j=1;j<n;j++){
13           if(a[j]>a[j-1]){
14             x=a[j];
15             a[j]=a[j-1];
16             a[j-1]=x;
17           }
18         }
19       }
20       for(int i=0;i<n;i++){
21         System.out.print(a[i]);
22         if(i!=n-1){
23           System.out.print(" ");
24         }
25       }
26   }
27 }

  程序设计思路:利用数组选择要排列的项

  知识点:数组

输入样例:

4
5 1 7 6

输出样例:

7 6 5 1
7-4 说反话-加强版 

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。

import java.util.Scanner;  
public class Main {  
  public static void main(String[] args) {  
    Scanner scanner = new Scanner(System.in);  
    String str = scanner.nextLine().trim();  
    String[] strs = str.split(" +");  
    for(int i=strs.length-1;i>=0;--i)  
    {  

        System.out.print(strs[i]);  
        if(i!=0)  
          System.out.print(" ");
    }  

  }  
}

  程序设计思路:利用nextLine()方法选择单词从而倒序输出

输入样例:

Hello World   Here I Come

输出样例:

Come I Here World Hello


7-5 简化的插入排序 

本题要求编写程序,将一个给定的整数插到原本有序的整数序列中,使结果序列仍然有序。

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner read=new Scanner(System.in 

);
        int n=read.nextInt();
        int a[]=new int[n+1];
        int i;
        for(i=0;i<n;i++){
            a[i]=read.nextInt();
}
        a[n]=read.nextInt();
        Arrays.sort(a);
        for(i=0;i<=n;i++){
            System.out.print(a[i]+" ");
        }
    }
}

  程序设计思路:利用nextInt()方法把制定整数插入到数组中

  知识点:数组 nextInt()方法

输入样例:

5
1 2 4 5 7
3

输出样例:

1 2 3 4 5 7 
7-6 交换最小值和最大值 (15 分)

本题要求编写程序,先将输入的一系列整数中的最小值与第一个数交换,然后将最大值与最后一个数交换,最后输出交换后的序列。

注意:题目保证最大和最小值都是唯一的。

import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner reader=new Scanner(System.in);
    int N=reader.nextInt();
    int a[]=new int[N];
    int b=0,c=0;
    for(int i=0;i<a.length;i++){
      a[i]=reader.nextInt();
    }
    for(int i=0;i<a.length;i++){
      if(a[i]<a[b]){
        b=i;
      }
    }
    int x=a[b];
    a[b]=a[0];
    a[0]=x;
    for(int i=0;i<a.length;i++){
      if(a[i]>a[c]){
        c=i;
      }
    }
    int y=a[c];
    a[c]=a[N-1];
    a[N-1]=y;
    for (int i=0;i<a.length;i++){
      System.out.print(a[i]+" ");
    }
  }
}

  程序设计思路:利用nextInt选择数组中要点换位置的数用for循环完成位置交换

  知识点: 指针 nextInt方法  for循环

输入样例:

5
8 2 5 1 4

输出样例:

1 2 5 4 8 
7-8 IP地址转换 (20 分)

一个IP地址是用四个字节(每个字节8个位)的二进制码组成。请将32位二进制码表示的IP地址转换为十进制格式表示的IP地址输出。

 1 import java.util.*;
 2 public class Main{
 3     public static void main(String[] args){
 4         Scanner read=new Scanner(System.in 
 5 
 6 );
 7         String n=read.nextLine();
 8         String a=n.substring(0,8);
 9         String b=n.substring(8,16);
10         String c=n.substring(16,24);
11         String d=n.substring(24,32);
12         int a1=Integer.parseInt(a,2);
13         int b1=Integer.parseInt(b,2);
14         int c1=Integer.parseInt(c,2);
15         int d1=Integer.parseInt(d,2);
16         System.out.print(a1+"."+b1+"."+c1+"."+d1);
17     }
18 }

    程序设计思路:利用nextLine()方法选取 返回值输出结果

    知识点:nextLine()方法  substring()方法

输入样例:

11001100100101000001010101110010

输出样例:

204.148.21.114

总结:第三次过程性考核结束了,一共三次考核,每一次的成绩都不是很理想但是真的尽力了。经历了三次考核,发现自己在java这方面真的不是学的很好,需要参考才能自己有思路,在做题上很慢很多格式上的错误都找不出来。课上老师讲得有点快很多知识点没有消化掉这次考核时间有点短所以没有总结得很好,希望在今后的学习中可以更加努力。

 
学习内容代码(行)博客(字)
第一次过程性考核70250
第二次过程性考核80300
第三次过程性考核87300
数组70 

运算符,表达式和

语句

100 
类与对象70 
子类与继承180 
常用使用类80 
合计737850
 

转载于:https://www.cnblogs.com/ddongqi/p/9901843.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值