重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
if(score==100){
公司主营业务:成都网站设计、网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出玉环免费做网站回馈大家。
System.out.println("满分")
}else if(score==0){
System.out.println("零分")
}else if(score100 score=60){
System.out.println("及格")
}else if(score60 score0){
System.out.println("及格")
}
排序可以使用Collections.sort。
例子如下:
import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class Main { private static class Student{ private String name; private float grade; public Student(String name, float grade) { this.name = name; this.grade = grade; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getGrade() { return grade; } public void setGrade(float grade) { this.grade = grade; } @Override public String toString() { return name + " " + grade; } } public static void main(String[] args) { ListStudent students = new ArrayList(); students.add(new Student("Tom", 86)); students.add(new Student("Jack", 70)); students.add(new Student("Mary", 90)); Collections.sort(students, new ComparatorStudent() { @Override public int compare(Student o1, Student o2) { if (o1.getGrade() - o2.getGrade() 0) { return 1; } else if (o1.getGrade() - o2.getGrade() 0) { return -1; } else { return 0; } } }); for (Student student : students) { System.out.println(student.toString()); } }}
使用要排序的字段来比较。就可以得到有序的列表。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入学生的分数:");
double score = input.nextDouble();
int level1,level2;
if(score=60.0 score=100.0){
System.out.print("该学生成绩为优秀!");
}
else if(score=0 score60.0){
System.out.print("该学生成绩为不及格!");
}
else{
System.out.print("您输入的成绩有误!");
}
}
}
Java 8 以上(包含java8) Lambda 方式,这种方式比较简洁,代码如下:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class App20 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ListFloat scores = new ArrayList();
System.out.println("请输入10个人的成绩:");
for (int i = 0; i 10; i++) {
scores.add(scanner.nextFloat());
}
float max = scores.stream().max((x, y) - Float点抗 pare(x, y)).get();
System.out.println("最高分:" + max);
float min = scores.stream().min((x, y) - Float点抗 pare(x, y)).get();
System.out.println("最低分:" + min);
float average = scores.stream().reduce(0.0f, Float::sum) / scores.size();
System.out.println("平均分:" + average);
scores.sort((x, y) - Float点抗 pare(x, y));
System.out.println("从小到大分数排序:");
scores.forEach(s - System.out.print(s + " "));
long n = scores.stream().filter(r - r average).count();
System.out.println("\n高于平均分的有" + n + "个");
}
}
传统方式,如下:
import java.util.Arrays;
public class App21 {
public static void main(String[] args) {
float[] scores = new float[] { 10f, 9f, 8f, 7f, 6f, 5f, 4f, 3f, 2f, 1f };
float max = Float.MIN_VALUE;
for(float score : scores) {
if (score max) {
max = score;
}
}
System.out.println("最高分:" + max);
float min = Float.MAX_VALUE;
for(float score : scores) {
if (score min) {
min = score;
}
}
System.out.println("最低分:" + min);
float sum = 0;
for(float score : scores) {
sum += score;
}
float average = sum / scores.length;
System.out.println("平均分:" + average);
// 从小到大排序
Arrays.sort(scores);
System.out.println("从小到大分数排序:");
for(float score : scores) {
System.out.print(score + " ");
}
int n = 0;
for(float score : scores) {
if (score average)
n++;
}
System.out.println("\n高于平均分的有" + n + "个");
}
}