编写程序:输入下表数据,并用结构体数组存放,按英语成绩升序排序后并输出。

编写程序:输入下表数据,并用结构体数组存放,按英语成绩升序排序后并输出。,第1张

闲着无聊 送你了

package test

public class Student {

private String name

private int age

public Student(String name,int age){

this.name=name

this.age=age

}

public String getName() {

return name

}

public void setName(String name) {

this.name = name

}

public int getAge() {

return age

}

public void setAge(int age) {

this.age = age

}

}

package test

import java.util.Arrays

public class Main {

public static void main(String[] args) {

Student [] studentInfo=new Student[5]

studentInfo[0]=new Student("张", 10)

studentInfo[1]=new Student("张", 9)

studentInfo[2]=new Student("李", 3)

studentInfo[3]=new Student("王1", 7)

studentInfo[4]=new Student("王2", 88)

Student [] newStudentInfo=Main.selectSort(studentInfo)

for(int i=0i<newStudentInfo.lengthi++){

System.out.println(newStudentInfo[i].getName()+":"+newStudentInfo[i].getAge())

}

}

public static Student [] selectSort(Student [] studentInfo){//选择排序算法

for (int i=0i<studentInfo.length-1 i++ ){

int min=i

for (int j=i+1j<studentInfo.length j++ ){

if (studentInfo[min].getAge()>studentInfo[j].getAge()){

min=j

}

}

if (min!=i){

Student temp=studentInfo[i]

studentInfo[i]=studentInfo[min]

studentInfo[min]=temp

}

}

return studentInfo

}

}

我只租搭会PB 在PB中是这样写的,供枯型高你参考没尺

int x,y

if x<=2 then

y=x*2

else

if 2<x<=10 then

y=x*(x+2)

else

y=x-10

end if

end if

#include <stdio.h>

int main()

{

    int w, h

 手羡拦   double bmi 

    scanf("issue your weight and height:%d%d", &w, &h)

    printf("your BMI:%d\n", (bmi = (703 * w / h / h)))

    printf("weight level: ") 

    if (bmi < 18.5)

        printf("偏轻\n")

    else if (bmi >= 18.5 毕胡&& bmi < 24.9)

        printf("正常\n")

    else if (bmi >= 25 && bmi < 29.9) 

        printf("超重\n")

    派贺else if (bmi >= 30)

        printf("肥胖") 

    return 0 

}

匆忙写的,没测试,可能有笔误,见谅


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12521859.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存