首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

编写一个Java的程序?

发布网友 发布时间:2022-04-22 06:52

我来回答

3个回答

热心网友 时间:2022-06-16 23:51

实现代码如下:

Student类:

public class Student {
private String name;
private String sex;
private int age;
private double chinese;
private double math;
private double english;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public double getChinese() {
return chinese;
}

public void setChinese(double chinese) {
this.chinese = chinese;
}

public double getMath() {
return math;
}

public void setMath(double math) {
this.math = math;
}

public double getEnglish() {
return english;
}

public void setEnglish(double english) {
this.english = english;
}
}

-----------------------------------------------------------------

StudentTest类:(测试类)

import java.util.Scanner;

public class StudentTest {
public static void main(String[] args) {
Student student = new Student();
Scanner sc = new Scanner(System.in);
System.out.println("请输入姓名:");
student.setName(sc.next());
System.out.println("请输入性别:");
student.setSex(sc.next());
System.out.println("请输入年龄:");
student.setAge(sc.nextInt());
System.out.println("请输入语文成绩、数学成绩、英语成绩:");
student.setChinese(sc.nextDouble());
student.setMath(sc.nextDouble());
student.setEnglish(sc.nextDouble());
Double count = student.getChinese()+ student.getMath()+student.getEnglish();
System.out.println("姓名:"+student.getName()+" 性别:"+student.getSex()+" 年龄:"+student.getAge());
System.out.println("总分:"+count+" 平均分:"+count/3);
}
}

运行结果为:

热心网友 时间:2022-06-16 23:51

public class Main {
public static void main(String[] args) {Scanner in=new Scanner (System.in);
int a,b,c,d,f;
char e;
String name;
while(in.hasNext()){
a=in.nextInt();
name=in.next();
e=in.next().charAt(0);
b=in.nextInt();
c=in.nextInt();
d=in.nextInt();
f=in.nextInt();
Student stu=new Student(a,name,e,b,c,d,f);
stu.shuchu(a,name,e);
stu.chengji(b, c, d, f);
}
}}

class Student{

private int 学号;
private String 姓名;
private char 性别;
private int 高数;
private int 英语;
private int c语言;
private int Java语言;
public Student(int 学号,String 姓名,char 性别,int 高数,int 英语,int c语言,int Java语言)
{
this.c语言=c语言;
this.Java语言=Java语言;
this.姓名=姓名;
this.学号=学号;
this.性别=性别;
this.英语=英语;
this.高数=高数;
}
public void shuchu(int 学号,String 姓名,char 性别)
{
System.out.print(学号+" "+姓名+" "+性别);
}
public void chengji(int 高数,int 英语,int c语言,int Java语言)
{
System.out.print(" "+高数+" "+英语+" "+c语言+" "+Java语言+" ");
System.out.println((高数+英语+c语言+Java语言)/4+" "+(高数+英语+c语言+Java语言));
}}

热心网友 时间:2022-06-16 23:52

/**
* <p>Description:
圣诞节的英文还不会拼呢 百度上搜了两遍 才写对</p>
*/
public class TestChristmas {
public static void main(String[] args) {
//叶子层
int level = 10;

//根层
int rootLevel = 2;
int spaceNum = level - 1;

//画叶子
// 为什么从1开始 不管了就是任性
for (int i = 1; i <= level; i++) {
spaceNum--;
for (int g = 0; g <= spaceNum; g++) {
System.out.print(" ");
}
for (int j = 1; j <= ((i * 2) -1); j++) {
System.out.print("*");
}
System.out.print("\n");
}

//画根
for (int i = 1; i <= rootLevel; i++) {
for (int g = 1; g < level; g++) {
System.out.print(" ");
}
System.out.print("*\n");
}
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com