java编程题(java编程题库和答案和解析)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

今天给各位分享java编程题的知识,其中也会对java编程题库和答案和解析进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

哪位好心人JAVA编程题可以帮忙写一下?

public class DividedByZeroException extends Exception {

private static final long serialVersionUID = 4420887449631055240L;

public String getMessage() {

return "除数不能为零";

}

}

上面是异常类DividedByZeroException的代码。

import java.util.Scanner;

public class Test {

@SuppressWarnings("resource")

public static void main(String[] args) {

System.out.print("请输入被除数:");

Scanner scanner1 = new Scanner(System.in);

int input1 = scanner1.nextInt();

System.out.print("请输入除数:");

Scanner scanner2 = new Scanner(System.in);

int input2 = scanner2.nextInt();

System.out.print("两个数相除结果为:");

if (input2 == 0) {

try {

throw new DividedByZeroException();

} catch (DividedByZeroException e) {

e.printStackTrace();

}

} else {

System.out.println(input1 / input2);

}

scanner1.close();

scanner2.close();

}

}

上面是测试类代码和运行结果,麻烦看一下是否能满足要求。

Java编程题编写一个Java Application程序包含Person类、Student(学?

public class Person {

private String name;//姓名

private String sex;//性别

public void sayHello() {

System.out.println("姓名:" + name);

System.out.println("性别:" + sex);

}

public Person() {

}

public Person(String name, String sex) {

this.name = name;

this.sex = sex;

}

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 class Student extends Person {

private String num;//学号

private String school;//学校

public void sayHello() {

super.sayHello();

System.out.println("学号:" + num);

System.out.println("学校:" + school);

}

public Student(String num, String school) {

this.num = num;

this.school = school;

}

public Student(String name, String sex, String num, String school) {

super(name, sex);

this.num = num;

this.school = school;

}

public Student() {

}

public String getNum() {

return num;

}

public void setNum(String num) {

this.num = num;

}

public String getSchool() {

return school;

}

public void setSchool(String school) {

this.school = school;

}

}

public class Test {

public static void main(String[] args) {

Student stu1 = new Student();

stu1.setName("张三");

stu1.setSex("男");

stu1.setNum("20211225001");

stu1.setSchool("北京大学");

Student stu2 = new Student("20211225002", "北京大学");

stu2.setName("李四");

stu2.setSex("男");

Student stu3 = new Student("王五", "女", "20211225003", "清华大学");

Person person1 = new Person();

person1.setName("赵六");

person1.setSex("女");

Person person2 = new Person("孙七", "女");

stu1.sayHello();

stu2.sayHello();

stu3.sayHello();

person1.sayHello();

person2.sayHello();

}

}

java入门编程题:某班有十位同学,请顺序输入十位同学的学号,保存在数组中,并输出所有同学的学号?

import java.util.Scanner;

public class Students {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

String[] students=new String[10];

String No=null;

for (int i = 0; i 10 ; i++) {

System.out.println("请输入学号:");

No=in.next();

students[i]=No;

}

System.out.println("学号是:");

for (String a:students) {

System.out.print(a+" ");

}

}

}

java编程题目,求求大佬救救我

这个题考察的是面向对象三大特性之一的继承。

子类继承父类。

项目结构如何所示:

Mobile 为父类,有一个属性:mobilePhone 代表电话号码。

有4个方法(功能):

1、获取手机号码:public String getMobilePhone(){}

2、存储手机号码:public void setMobilePhone(String mobilePhone) {}

3、拨打电话号码:public void callOnMobilePhone(){}

4、挂断电话:public void callOffPhone(){}

具体代码如下所示:、

--------------------------------------mobilePhone 开始--------------------------------------

/**

* @author 冯修远

* 创建一个第一代手机类,要求包含手机号码信息,并包含获取电话号码,

* 存储电话号码、拨打电话号码和挂断电话等功能。并以此为父类,派生

* 出子类第二代手机类,增加拍照功能。以第二代手机类来生成对象并

* 模拟实现拨打电话、挂断电话拍照等功能。

*/

public class Mobile {

//手机号码

private String mobilePhone;

/**

* 获取手机号码

* @return

*/

public String getMobilePhone() {

return mobilePhone;

}

/**

* 存储手机号码

* @param mobilePhone

*/

public void setMobilePhone(String mobilePhone) {

this.mobilePhone = mobilePhone;

}

/**

* 拨打电话号码

*/

public void callOnMobilePhone(){

System.out.println("拨打电话号码:"+mobilePhone);

}

/**

* 挂断电话

*/

public void callOffPhone(){

System.out.println("挂断与:"+mobilePhone+"的通话");

}

}

--------------------------------------mobilePhone 结束--------------------------------------

PhotoMobile 为子类或者叫派生类,继承自父类:Mobile

同时也继承了父类的4个方法,但父类的属性因为我设置的是private,所以继承不了。

PhotoMobile 的代码如下图所示:

最后一个类,也就是测试类,用于创建第二代手机的对象,并调用相应的功能,如下图所示:

最终,程序的运行结果如下图所示:

我是冯修远,如果我的答案对您有帮助的话,请采纳以帮助更多的人,如果还有其它的问题,也请关注我,私信我,谢谢!

有关java编程题目?

按照题目要求编写的圆,圆锥和测试类的Java程序如下

Test.java文件内容如下

class Circle{

private double r;

private String color;

public Circle(double r){

this.r=r;

}

public double area(){

return Math.PI*r*r;

}

public double perimeter(){

return Math.PI*2*r;

}

public double getR(){

return this.r;

}

public void setR(double r){

this.r=r;

}

public String getColor(){

return this.color;

}

public void setColor(String color){

this.color=color;

}

public String toString(){

return "圆的半径为"+r+",颜色为"+color;

}

}

class Cone{

private Circle c;

private double h;

private String color;

public Cone(Circle c,double h){

this.c=c;

this.h=h;

}

public double volume(){

return 1.0/3*c.area()*h;

}

public Circle getCircle(){

return this.c;

}

public void setCircle(Circle c){

this.c=c;

}

public double getH(){

return this.h;

}

public void setH(double h){

this.h=h;

}

public String getColor(){

return this.color;

}

public void setColor(String color){

this.color=color;

}

public String toString(){

return "圆锥的底面积为"+c.area()+",高为"+h+",颜色为"+color;

}

}

public class Test{

public static void main(String[] args){

Circle circle1=new Circle(2.5);

circle1.setColor("红色");

System.out.println(circle1.toString());

System.out.println("圆的面积为"+circle1.area());

System.out.println("圆的周长为"+circle1.perimeter());

Cone circlar1=new Cone(circle1,2.7);

circlar1.setColor("蓝色");

System.out.println(circlar1.toString());

System.out.println("圆锥的体积为"+circlar1.volume());

}

}

关于java编程题和java编程题库和答案和解析的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

发布于 2023-04-09 22:04:37
收藏
分享
海报
25
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了