• java 实例 数组


    package rj435;
    
    import java.util.Scanner;
    /*编程实现:从键盘录入两组数,每组5个元素,分别存储在B和C数组中,
    然后把两个数组反向相加,相加的结果存储在A数组中,
    然后再把A数组的元素按升序排序之后输出。*/
    public class Arrays {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int[] B = new int[5];
            int[] C = new int[5];
            int[] A = new int[5];
            System.out.println("请输入B数组包含的5个元素:");
            B[0] = input.nextInt();
            B[1] = input.nextInt();
            B[2] = input.nextInt();
            B[3] = input.nextInt();
            B[4] = input.nextInt();
            System.out.println("请输入C数组包含的5个元素:");
            C[0] = input.nextInt();
            C[1] = input.nextInt();
            C[2] = input.nextInt();
            C[3] = input.nextInt();
            C[4] = input.nextInt();
            System.out.print("A数组的元素为:	");
            for (int i = 0; i < B.length; i++) {
                A[0]=B[0]+C[4];
                A[1]=B[1]+C[3];
                A[2]=B[2]+C[2];
                A[3]=B[3]+C[1];
                A[4]=B[4]+C[0];
                System.out.print(A[i] + "	");
            }
            for (int i = 0; i < A.length - 1; i++) {
                for (int j = 0; j < A.length - i - 1; j++) {
                    if (A[j] > A[j + 1]) {
                        int temp = A[j];
                        A[j] = A[j + 1];
                        A[j + 1] = temp;
                    }
                }
    
            }
            System.out.print("最终排序结果:	");
            for (int a = 0; a < A.length; a++) {
                System.out.print(A[a] + "	");
            }
        }
    
    }
  • 相关阅读:
    POJ 2411 Mondriaan's Dream -- 状压DP
    codeforces 792A-D
    codeforces 796A-D
    Acdream1201 SuSu's Power
    HDU 2818 Building Block
    C# NetStream
    基于Duff's Device的C简易无栈协程实现
    CentOS 多版本 GCC 共存
    2017杭电多校第一场
    2019杭电多校第十场
  • 原文地址:https://www.cnblogs.com/Angella/p/6858745.html
Copyright © 2020-2023  润新知