几个简单的JAVA问题

来源:百度知道 编辑:UC知道 时间:2024/06/19 03:11:40
1. Write a method that will display numbers from 1 to n. The numbers are separated by one space. The method signature is as follows:
public static void displayNumber(int n)
2. Write a program that passes an unspecified number of integers as one command-line argument and displays their total. For example, if you run the program using the following argument,
java Sum “1 2 3”
The output is
Sum is 6.
3. Write a main method to let a user enter student scores, and display the max, min, and average of the score. The input 0 signifies the end of input.
4. Write a method that gets an element from an array randomly. The method signature is as follows:
public static double getRandomElement(double[] a)
5. Write a method to find the max in an array of double values. The method signature is as follows:
public static double max(double[] a)
大哥大姐帮帮忙,谢谢了!可以发到我邮箱里面:gm11111@qq.com
受不了你们了,都说简单了还不愿意动手做一下.

大家也受不了你,这么简单的题多半就是什么都不会来问作业答案的,任谁看着也烦。

void displayAnumber(int n) {
for(int i=1;i<n;i++)
System.out.print(i+" ");
System.out.print(n);
}

public static void main(String[] args) {
int i=0;
for(String s:args[0].split(" ")) i+=Integer.parseInt(s);
System.out.printf("Sum is %d.", i);
}

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int i;
int avg=0, max=Integer.MIN_VALUE, min=Integer.MAX_VALUE, c=0;
while((i=s.nextInt())!=0) {
a+=i;
if(i>max) max=i;
if(i<min) min=i;
c++;
}
System.out.printf("Max %d Min %d Avg %d", max, min, avg/c);
}

public static double max(double[] a) {
double m=Double.NEGATIVE_INFINITY;
for(double d:a) if(d>m) m=d;
return m;
}

学习是一个过程,不要心急,是你英文看不懂还是真正题目不会做,这么简单!硬是不会找我!

的确算简单,自己动手吧。

这个也贴!!?
而且只有20分/5

英文的