java基础2

1、设计一个程序显示一个班的平均成绩,并统计一个班成绩不及格(分数小于60分)的学生人数。

import java.util.Scanner;
public class Hello {
	public static void main(String [] args) {
		int size=0;
		//用变量count记录不合格人数
		int count=0;
		double grade=0;
		double averageGrade=0;
		
		Scanner sc=new Scanner(System.in);
		System.out.println("shuruxueshengchengji: ");
		grade=sc.nextDouble();
		while(grade != -1) {
			if(grade<60) {
				count++;
			}
			averageGrade=averageGrade+grade;
			size++;
			grade=sc.nextDouble();
		}
		averageGrade=averageGrade/size;
		
		System.out.println("pingjunchengji: "+averageGrade);
		System.out.println("bujigerenshu: "+count);
	}
}

java基础2_第1张图片

import java.util.Scanner;
public class Hello {
	public static void main(String [] args) {
		double grade=70.2;
		double a;
		if(grade - 70 == 0.2) {
			System.out.println("xiangdeng");
		}
		else {
			System.out.println("buxiangdeng");
		}
		a=grade-70;
		System.out.println(a);
	}
}

用数组显示一个班学生的平均成绩和每个人的成绩

import java.util.Scanner;
public class Hello{
	public static void main(String [] args){
		int SIZE=5;
		
		double grade[]=new double[SIZE];
		double averageGrade=0;
		
		Scanner sc=new Scanner(System.in);
		
		for(int i=0;i<SIZE;i++) {
			grade[i]=sc.nextDouble();
		}
		for(int i=0;i<SIZE;i++) {
			averageGrade=averageGrade+grade[i];
		}
		averageGrade=averageGrade/SIZE;
		System.out.println("pingjunchengji: "+averageGrade);
		for(int i=0;i<SIZE;i++) {
			System.out.println("xueshengchengji: "+grade[i]);
		}
	}
}
import java.util.Scanner;
public class Hello{
	public static void main(String [] args){
		int SIZE=5;
		
		double grade[]=new double[SIZE];
		double averageGrade=0;
		double maxGrade=0;
		
		Scanner sc=new Scanner(System.in);
		
		for(int i=0;i<SIZE;i++) {
			grade[i]=sc.nextDouble();
		}
		
		maxGrade=grade[0];
		for(int i=0;i<SIZE;i++) {
			averageGrade=averageGrade+grade[i];
			if(maxGrade<grade[i]) {
				maxGrade=grade[i];
			}
		}
		
		averageGrade=averageGrade/SIZE;
		System.out.println("pingjunchengji: "+averageGrade);
		System.out.println("zuigaochengji: "+maxGrade);
		for(int i=0;i<SIZE;i++) {
			System.out.println("xueshengchengji: "+grade[i]);
		}
	}
}

今晚over~

你可能感兴趣的:(java学习,java,开发语言)