Java编程、输入数字个数、平均数、最小值、最大值减去最小值、
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/07/15 19:43:31
Java编程、输入数字个数、平均数、最小值、最大值减去最小值、
write a JAVA program to read in a sequence of integers and print out the following quantities,each on a new line and in the following order,your program should be:
1) the number of integers read in.
2) the average value- which need not be an integer.注意,平均值不是实数!
3) the minimum value of the integers.
4) the maximum difference between any of the integers.
以上要求顺序不能颠倒、跪求!
write a JAVA program to read in a sequence of integers and print out the following quantities,each on a new line and in the following order,your program should be:
1) the number of integers read in.
2) the average value- which need not be an integer.注意,平均值不是实数!
3) the minimum value of the integers.
4) the maximum difference between any of the integers.
以上要求顺序不能颠倒、跪求!
![Java编程、输入数字个数、平均数、最小值、最大值减去最小值、](/uploads/image/z/281675-11-5.jpg?t=Java%E7%BC%96%E7%A8%8B%E3%80%81%E8%BE%93%E5%85%A5%E6%95%B0%E5%AD%97%E4%B8%AA%E6%95%B0%E3%80%81%E5%B9%B3%E5%9D%87%E6%95%B0%E3%80%81%E6%9C%80%E5%B0%8F%E5%80%BC%E3%80%81%E6%9C%80%E5%A4%A7%E5%80%BC%E5%87%8F%E5%8E%BB%E6%9C%80%E5%B0%8F%E5%80%BC%E3%80%81)
测试通过,基本满足你题目要求,写得不太好
import java.util.*;
import java.util.regex.*;
public class t10
{
public static void main(String [] args)throws InterruptedException
{
Scanner in=new Scanner(System.in);
System.out.println("输入一组数,用逗号分开");
String s = in.next();
number a = new number(s);
average b = new average(s);
min c =new min(s);
dif d= new dif(s);
Thread t1=new Thread(a);
Thread t2=new Thread(b);
Thread t3=new Thread(c);
Thread t4=new Thread(d);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
//整数个数
class number implements Runnable
{
int sum=0;
List dlist=new ArrayList();
public number(String a)
{
String[] str = a.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
sum=dlist.size();
}
public void run()
{
System.out.println("整数的个数为:"+sum);
}
}
//平均数
class average implements Runnable
{
double sum=0;
double aver=0;
public average(String b)
{
String[] str = b.split(",");
double [] num =new double[str.length];
for(int i = 0; i < str.length; i++)
{
num[i]=Double.parseDouble(str[i]);
}
for (int i = 0; i < num.length; i++)
{
sum=sum+num[i];
}
aver=(double)(sum/num.length);
}
public void run()
{
try{
Thread.sleep(100);
}catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("平均数为:"+aver);
}
}
//最小的整数
class min implements Runnable
{
double m=0;
List dlist=new ArrayList();
public min(String c)
{
String[] str = c.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
}
public void run()
{
try{
Thread.sleep(300);
}catch(InterruptedException e)
{
e.printStackTrace();
}
if(dlist.size()!=(0))
{
m=Collections.min(dlist);
System.out.println("最小整数为:"+m);
}
else
{System.out.println("最小整数为:没有整数");}
}
}
//两个相差最大的整数
class dif implements Runnable
{
double min=0;
double max=0;
double bet=0;
List dlist=new ArrayList();
public dif(String d)
{
String[] str = d.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
}
public void run()
{
try{
Thread.sleep(500);
}catch(InterruptedException e)
{
e.printStackTrace();
}
if(dlist.size()!=(0) && dlist.size()!=(1))
{
min=Collections.min(dlist);
max=Collections.max(dlist);
bet=max-min;
System.out.println("最小整数和最大整数相差:"+bet);
}
else
{
System.out.println("最小整数和最大整数相差:整数少于2个无法计算");
}
}
}
import java.util.*;
import java.util.regex.*;
public class t10
{
public static void main(String [] args)throws InterruptedException
{
Scanner in=new Scanner(System.in);
System.out.println("输入一组数,用逗号分开");
String s = in.next();
number a = new number(s);
average b = new average(s);
min c =new min(s);
dif d= new dif(s);
Thread t1=new Thread(a);
Thread t2=new Thread(b);
Thread t3=new Thread(c);
Thread t4=new Thread(d);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
//整数个数
class number implements Runnable
{
int sum=0;
List dlist=new ArrayList();
public number(String a)
{
String[] str = a.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
sum=dlist.size();
}
public void run()
{
System.out.println("整数的个数为:"+sum);
}
}
//平均数
class average implements Runnable
{
double sum=0;
double aver=0;
public average(String b)
{
String[] str = b.split(",");
double [] num =new double[str.length];
for(int i = 0; i < str.length; i++)
{
num[i]=Double.parseDouble(str[i]);
}
for (int i = 0; i < num.length; i++)
{
sum=sum+num[i];
}
aver=(double)(sum/num.length);
}
public void run()
{
try{
Thread.sleep(100);
}catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("平均数为:"+aver);
}
}
//最小的整数
class min implements Runnable
{
double m=0;
List dlist=new ArrayList();
public min(String c)
{
String[] str = c.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
}
public void run()
{
try{
Thread.sleep(300);
}catch(InterruptedException e)
{
e.printStackTrace();
}
if(dlist.size()!=(0))
{
m=Collections.min(dlist);
System.out.println("最小整数为:"+m);
}
else
{System.out.println("最小整数为:没有整数");}
}
}
//两个相差最大的整数
class dif implements Runnable
{
double min=0;
double max=0;
double bet=0;
List dlist=new ArrayList();
public dif(String d)
{
String[] str = d.split(",");
for(int i = 0; i < str.length; i++)
{
Pattern pattern = Pattern.compile("[0-9]+");
Matcher matcher = pattern.matcher((CharSequence) str[i]);
boolean result = matcher.matches();
if (result) {
dlist.add(Double.parseDouble(str[i]));}
}
}
public void run()
{
try{
Thread.sleep(500);
}catch(InterruptedException e)
{
e.printStackTrace();
}
if(dlist.size()!=(0) && dlist.size()!=(1))
{
min=Collections.min(dlist);
max=Collections.max(dlist);
bet=max-min;
System.out.println("最小整数和最大整数相差:"+bet);
}
else
{
System.out.println("最小整数和最大整数相差:整数少于2个无法计算");
}
}
}
Java编程、输入数字个数、平均数、最小值、最大值减去最小值、
求一个C语言编程 输入N个数 求最大值 最小值 平均数
java编程,输出3个数中的最大值和最小值
vfp的一道编程题,输入任意的几个数,输出最大值、最小值、总和、平均数.
求救,新手上路,求一个 Java程序,计算一组数字的个数,最大值 最小值 平均值,最大值和最小值的差.
如何设计“输入m个数,求其最大值、最小值、平均数”的c程序?
如何设计“输入m个数,求其最大值、最小值、平均数”的c程序
c语言编程,第一行输入数据个数,第二行输入数据,输出数据中最大值与最小值
输入10个数 最后输出最大值和最大值的个数 最小值和最小值的个数
求一个C程序,输入一组数字,显示其个数,最大值,最小值,平均值,方差,标准差
小弟求助一题JAVA题目,2.连续输入一组数字,求出其中最大值和最小值.(要用while),
任意输入n个数,输出其中最大值与最小值,并输出它在序列中的位置!C语言编程