//输入数字个数来产生数字并且比较大小

import java.util.Scanner;

public class Test1 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入你要输入的数字个数:");

        int num = sc.nextInt();

        int[] array = new int[num];

        for (int i = 0; i < array.length; i++) {

            System.out.println("请输入第" + (i + 1) + "个数。");
            array[i] = sc.nextInt();
        }

        System.out.println("最大值:" + getArrayMax(array));
        System.out.println("最小值:" + getArrayMin(array));

    }

    public static int getArrayMax(int[] array) {

        int max = array[0];

        for (int i = 1; i < array.length; i++) {

            max = (max < array[i]) ? array[i] : max;
        }

        return max;

    }

    public static int getArrayMin(int[] array) {

        int min = 0;

        for (int i = 1; i < array.length; i++) {

            min = (array[min] > array[i]) ? i : min;
        }

        return array[min];
    }
    
    

}

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        /*
         * int num=123; int sum;
         *
         * int a=num/100%10; int b=num/10%10; int c=num%10;
         *
         * sum=a+b+c;
         *
         * System.out.println(sum);
         */

        Scanner input = new Scanner(System.in);
        int max = 0;
        int min = 0;

        for (int i = 0; i < 5; i++) {
            System.out.println("请输入第" + (i + 1) + "个数");

            int number = input.nextInt();

            if (i == 0) {

                max = number;
                min = number;
            } else {

                if (max < number) {

                    max = number;
                }
                if (min > number) {

                    min = number;
                }
            }
        }

        System.out.println("最大值为:" + max);
        System.out.println("最小值为:" + min);
    }

}

-----------------------------------------------------------------------------------------

import java.util.Scanner;

public class Test22 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner input = new Scanner(System.in);

        System.out.println("请输入十个成绩 :");

        int[] score = new int[10];

        int max = 0;
        double avg = 0;
        int sum = 0;
        int min = score[0];

        for (int i = 0; i < score.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个成绩 :");
            score[i] = input.nextInt();

            if (i == 0) {
                max = score[i];
                min = score[i];
            } else {

                if (score[i] > max) {
                    max = score[i];
                }

                if (score[i] < min) {
                    min = score[i];
                }

            }

            sum = sum + score[i];
        }

        avg = sum / 10;
        System.out.println("最高分是:" + max);
        System.out.println("最低分是:" + min);
        System.out.println("平均分是:" + avg);
    }

}

Java开发中经典的小实例-(比较输入数值的最大值、最小值和平均值)的更多相关文章

  1. Java开发中经典的小实例-(输入三个数字判断三角形类型)

    import java.util.Scanner;public class threeTest {    public static void main(String[] args) {       ...

  2. Java开发中经典的小实例-(打印输入重复的值)

    import java.util.ArrayList;import java.util.Scanner;public class Test8 {    public static void main( ...

  3. Java开发中经典的小实例-(二分法)

    public int binarySearch(int[] data,int aim){//以int数组为例,aim为需要查找的数 int start = 0; int end = data.leng ...

  4. Java开发中经典的小实例-(while(参数){})

    import java.util.Scanner;public class Test_while {    public static void main(String[] args) {       ...

  5. Java开发中经典的小实例-(swich(){case:参数break;default: break;})

    import java.util.Scanner;public class Test6 {    public static void main(String[] args) {        // ...

  6. Java开发中经典的小实例-(能被3整除,并且十个数换一行)

    import java.util.Scanner;public class Test15 {    public static void main(String[] args) {        // ...

  7. Java开发中经典的小实例-(do{}while())

    import java.util.Scanner;public class Test13 {    public static void main(String[] args) {        // ...

  8. Java开发中经典的小实例-(随机产生验证码)

    import java.util.Scanner;public class Test10 {    public static void main(String[] args) {        // ...

  9. Java开发中经典的小实例-(随机数)

    import java.util.Random;//输出小于33的7个不相同的随机数public class probability {    static Random random = new R ...

随机推荐

  1. IOS第18天(9,核心动画-动画组)

    ****动画组 // 核心动画都是假象,不能改变layer的真实属性的值// 展示的位置和实际的位置不同.实际位置永远在最开始位置 #import "HMViewController.h&q ...

  2. 使用JAXP对XML文档进行DOM解析

    import java.io.FileOutputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers. ...

  3. 【iCore3 双核心板】例程十六:USB_HID实验——双向数据传输

    实验指导书及代码包下载: http://pan.baidu.com/s/1bojcVoV iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  4. Windows 10输入法已禁用IME无法输入中文怎么办

    Windows 10输入法已禁用IME无法输入中文怎么办 | 浏览:10453 | 更新:2015-03-01 14:46 | 标签:windows 1 2 3 4 5 分步阅读 Windows10系 ...

  5. Theos

    一.安装 1.配置环境变量 (每次 terminal 重新启动需要配置) $ export THEOS=/opt/theos 2.下载 Theos $ sudo git clone git://git ...

  6. C#编程利器之二:结构与枚举(Structure and enumeration)【转】

    C#编程利器之二:结构与枚举(Structure and enumeration) 在上一篇文章中,介绍了类如何封装程序中的对象.而实际中,出了类可以封装对象外,结构和枚举也可以封装一些对象,本文将着 ...

  7. Ajaxupload.js上传插件使用

    注意一下火狐,360IE78下的坑: 返回过来的response在不同浏览器下的字符串不一致 // response(chrome):<pre style="word-wrap: br ...

  8. android如何获取到启动类的包和类路径

    ArrayList<String> list = new ArrayList<String>(); private List<ResolveInfo> mApps; ...

  9. windows的Timer和写文件方式串口注意!

    1.Timer要读取并分发消息,才能触发自定义回调函数 SetTimer(NULL, 1, 40, (TIMERPROC)TimerProc); while(GetMessage(&msg, ...

  10. APICloud:轻松6步完成App软件开发

    现如今,谁不知道App绝对就是OUT,谁不用App简直没法过日子!但是说到App软件开发,不懂编程,不懂技术的人就一脸懵圈.在门外汉来看,App软件开发是一件非常困难的事情,然而APICloud却说, ...