用数组完成简单运算(JAVA数组课后作业)

在这里插入图片描述

package com.homework;

import java.util.Scanner;
/*
作者:mengling 2227287556@qq.com
时间:2021.3.27
 */

public class HomeWork1 {
    public static void main(String[] args) {
       String []arr=new String[5];
       Scanner input = new Scanner(System.in);
        System.out.println("请输入五个汉字");
        for (int i = 0; i < 5; i++) {
            arr[i]=input.next();

        }
        for (int i = 4; i >= 0; i--) {
            System.out.println(arr[i]);

        }
        }
    }

在这里插入图片描述
在这里插入图片描述

package com.homework;
/*
作者:mengling 2227287556@qq.com
时间:2021.3.27
 */

public class Homework2 {
    public static void main(String[] args) {
        boolean Ling = false ;
        int []array = new int[]{1,3,-1,5,-2};
        int temp=0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 1; j < (array.length-i); j++) {
                if (array[j-1]>array[j]){
                    temp = array[j-1];
                    array[j-1]=array[j];
                    array[j]=temp;
                    Ling=true;
                }

            }
            if (!Ling){
                break;
            }

        }
        for (int i = 0; i < 5; i++) {
            System.out.println(array[i]);

        }
    }
}

在这里插入图片描述

package com.homework;

import java.util.Scanner;
/*
作者:mengling 2227287556@qq.com
时间:2021.3.27
 */
public class HomeWork3 {
    public static void main(String[] args) {
        int not = 0,yes = 0,one = 0,two = 0,three = 0;
        int[]shuzu=new int[10];
        Scanner input = new Scanner(System.in);
        System.out.println("请输入十个数");
        for (int i = 0; i < 10; i++) {
            shuzu[i]=input.nextInt();
            if (shuzu[i]==1||shuzu[i]==2||shuzu[i]==3){
                yes++;
            }
            else {
                not++;
            }
            if (shuzu[i]==1){
                one++;
            }
            if (shuzu[i]==2){
                two++;
            }
            if (shuzu[i]==3){
                three++;
            }
        }
        System.out.print("输入的十个数为:");
        for (int i = 0; i < 10; i++) {
            System.out.print(shuzu[i]+"   ");

        }
        System.out.println();
        System.out.println("输入1的个数:"+one);
        System.out.println("输入2的个数:"+two);
        System.out.println("输入3的个数:"+three);
        System.out.println("非法数字的个数:"+not);
    }
}

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值