请告诉我一个算法,该算法可以找到没有数组的10个数字的最大值和最小值. [英] Please tell me an algorithm that finds the max and min of 10 numbers without array.

查看:79
本文介绍了请告诉我一个算法,该算法可以找到没有数组的10个数字的最大值和最小值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

软件包maxminjava;
导入java.util.Scanner;
公共类Main {

公共静态void main(String [] args){

扫描仪输入=新的Scanner(System.in);
整数;
for(int counter = 0; counter< = 10; counter ++)
System.out.println("enter number:");
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
数字= input.nextInt();
}

}
你的帮助. :)

package maxminjava;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);
int numbers;
for(int counter=0;counter<=10 ; counter++)
System.out.println("enter numbers:");
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
numbers=input.nextInt();
}

}
u for your help. :)

推荐答案

将整数存储在数组中,例如item.
然后
Store the integers inside an array, say item.
Then
max = min = item[0];
for (int i=1; i<10; i++)
{
  if (min > item[i]) min = item[i];
  if (max < item[i]) max = item[i];
}


:)


这篇关于请告诉我一个算法,该算法可以找到没有数组的10个数字的最大值和最小值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆