重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import java.util.Scanner;
公司主营业务:成都网站设计、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出洛浦免费做网站回馈大家。
public class Demo {
public static void main(String[] args) {
int[][] a = new int[10][3];
String str[] = { "A", "B", "C" };
Scanner scan = new Scanner(System.in);
for (int i = 0; i 2; i++) {
for (int j = 0; j 3; j++) {
System.out.print("输入第" + (1 + i) + "位同学的" + str[j] + "的分数:");
a[i][j] = scan.nextInt();
}
}
for (int i = 0; i 2; i++) {
for (int j = 0; j 3; j++) {
System.out.println("第" + (1 + i) + "位同学的" + str[j] + "的分数为:"+a[i][j]);
}
}
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class GradeList {
public static void main(String[] args) {
ArrayListInteger list = new ArrayList();
Scanner in = new Scanner(System.in);
int grade;
System.out.print("请输入成绩,以空格隔开,键入-1结束:");
while ((grade = in.nextInt())!=-1){
if(grade=0grade=100)
list.add(grade);
}
System.out.println("实际统计的人数为:"+list.size()+"\n实际统计的成绩为:"+list);
System.out.println("平均分:"+getAvg(list));
System.out.println("最高分:"+getMax(list));
System.out.println("最低分:"+getMin(list));
System.out.println("不及格:"+getBad(list));
}
public static double getAvg(ArrayListInteger list){
int sum = 0;
for (int i = 0; i list.size(); i++) {
sum += list.get(i);
}
return (double)sum/list.size();
}
public static int getMax(ArrayListInteger list){
Collections.sort(list);
return list.get(list.size()-1);
}
public static int getMin(ArrayListInteger list){
Collections.sort(list);
return list.get(0);
}
public static ArrayList getBad(ArrayListInteger list){
Collections.sort(list);
ArrayListInteger badGradeList = new ArrayListInteger();
for (int index=0; index list.size(); index++) {
int grade = list.get(index);
if (grade60)
badGradeList.add(grade);
}
return badGradeList;
}
}
main方法
求平均、最高、最低、不及格方法
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int[] arr=new int[5];
float ave=0;
System.out.print("请输入5个同学的java成绩:");
for(int i=0;i5;i++)
{
arr[i]=sc.nextInt();
ave+=arr[i];
}
System.out.printf("总分 = %d; 平均分 = %.1f",(int)ave,ave/5);
System.out.println();
sc.close();
}
}
主要是下标做了,记住数组是用0开始,现在调通了
import java.util.Scanner;
public class Admin {
public static void main(String... args) {
Scanner reader = new Scanner(System.in);
System.out.println("输入用户个数:");
int score = reader.nextInt();
double score1[] = new double[score];
System.out.println("输入用户成绩:");
for (int i = 0; i score1.length; i++) {
double s = reader.nextDouble();
score1[i] = s;
}
System.out.println("输入查找学生");
int n = reader.nextInt();
if (n == score) {
System.out.println("第" + score + "学生成绩是:" + score1[score - 1]);
}
}
}