java程序设计编程题(Java程序设计题)

程序设计 606
本篇文章给大家谈谈java程序设计编程题,以及Java程序设计题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、3道java编程题,求解

本篇文章给大家谈谈java程序设计编程题,以及Java程序设计题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

3道java编程题,求解

package TestPerson;

/**

 * (1) 编写程序实现如下功能:已知Person类包含三个公共成员变量(姓名、性别、年龄)和一个构造方法,

 * Student类是Person类的派生类,包含两个新的公共成员变量(学号、班号)、两个公共方法(修改年龄、显示基本信息)及一个构造方法。

 * 在测试类Test1中,定义一组学生对象,并初始化他们的基本信息,然后依次输出。

 */

public class Test1 {

public static void main(String[] args) {

Student[] student = new Student[3];

student[0] = new Student("小李", "男", 12, 20181101, 01);

student[1] = new Student("小南", "女", 13, 20001102, 01);

student[2] = new Student("小李", "男", 12, 20181103, 01);

for(Student stu : student) {

stu.showInformation();

}

}

}

class Person {

public String name;

public String sex;

public int age;

public Person(String name, String sex, int age) {

super();

this.name = name;

this.sex = sex;

this.age = age;

}

}

class Student extends Person {

public long studentId;

public long classId;

public void setAge(int age) {

age = this.age;

}

public void showInformation() {

System.out.println("我的姓名是" + name + "," + "我的性别是" + sex + "," + "我的年龄是" + age 

+ "岁," + "我的学号是" + studentId + "," + "我的班号是" + classId + "班");

}

public Student(String name, String sex, int age, long studentId,

long classId) {

super(name, sex, age);

this.studentId = studentId;

this.classId = classId;

}

}

不可否认,我现在是有点闲,所以我就帮你写第一个吧,至于后面两个,我就不写了,看看还有没有其他人有点闲时间,看缘分吧

运行结果:

我的姓名是小李,我的性别是男,我的年龄是12岁,我的学号是20181101,我的班号是1班

我的姓名是小南,我的性别是女,我的年龄是13岁,我的学号是20001102,我的班号是1班

我的姓名是小李,我的性别是男,我的年龄是12岁,我的学号是20181103,我的班号是1班

有几个java编程的题各位好心人有时间的能帮忙写下吗?

没那么多时间,帮着写个第1题吧

// 编写求一个整数数组A[10,15,12,9,7]中最小元素min和元素之和sum的

int [] a = {10,15,15,9,7};

// 最小元素

int min=0;

// 数组和

int sum=0;

for(int i=0; ia.length; i++ ){

sum += a[i];

if(i == 0){

min = a[i];

}else{

if(a[i]  min){

min = a[i];

}

}

}

System.out.println("当前数组中最小的元素值是: "+min);

System.out.println("当前数组和是: "+sum);

一道简单的java编程题?

import java.text.ParseException;

import java.text.SimpleDateFormat;

//日期类

public class Date {

private String year;

private String month;

private String day;

public Date(String year, String month, String day) {

this.year = year;

this.month = month;

this.day = day;

}

public void format(){

System.out.println(day + "/" + month + "/" + year);

}

public void calculate(){

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");

try {

java.util.Date startDate = sdf.parse(year + "/" + "01" + "/" + "01");

java.util.Date inputDate = sdf.parse(year + "/" + month + "/" + day);

long resultDay = (inputDate.getTime() - startDate.getTime())/(24 * 1000 * 60 * 60);

System.out.println("第" + (resultDay + 1) + "天");

} catch (ParseException e) {

e.printStackTrace();

}

}

}

//测试类

public class Test {

public static void main(String[] args) {

Date date1 = new Date("2020","04","11");

Date date2 = new Date("2020","01","02");

date1.format();

date1.calculate();

date2.format();

date2.calculate();

}

}

java程序设计编程题的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java程序设计题、java程序设计编程题的信息别忘了在本站进行查找喔。

扫码二维码