JAVA简答题与编程

JAVA简答题与编程,第1张

11:B类继承了A类,B是A的子类,A是B的父类

12:多态

13:I love: java and 268

2:// 仅供参考

3// 仅供参考

class car

{

private String carName;

private String carColor;

public Car(String carName, String carColor) {

thiscarColor=carColor;

thiscarName=carName;

}

public void setcarName(String carName)

{

thiscarName=carName;

}

public void setcarColor(String carColor)

{

thiscarColor=carColor;

}

public String getcarName()

{

return carName;

}

public String getcarColor()

{

return carColor;

}

void run()

{

Systemoutprintln("Car can run");

}

public class Rectangle { private double width; private double height; private String colour; public double getWidth() { return width; } public void setWidth(double width) { thiswidth = width; } public double getHeight() { return height; } public void setHeight(double height) { thisheight = height; } public String getColour() { return colour; } public void setColour(String colour) { thiscolour = colour; } public Rectangle(double width, double height, String colour) { super(); thiswidth = width; thisheight = height; thiscolour = colour; } public Rectangle() { super(); } public void getArea(double width, double height, String colour){ Systemoutprintln("矩形的宽:"+width+"cm"); Systemoutprintln("矩形的高:"+height+"cm"); Systemoutprintln("矩形的颜色 :"+colour); Systemoutprintln("矩形的面积 :" +widthheight); } public static void main(String[] args) { Rectangle r1= new Rectangle(); r1getArea(40, 20, "Red色"); Rectangle r2= new Rectangle(); r2getArea(30, 60, "红色"); } }

public class Animal {

public String name;

public int age;

public String gender;

public String color;

public Animal(int age) {

thisage = age;

}

public void happy() {}

public void unhappy(){}

}

public class Dog extends Animal {

public Dog(int age) {

spuer(age);

}

private void actAsDoorkeeper() {}

private void eatBone() {}

}

public class Cat extends Animal {

public Cat(int age) {

super(age);

}

private void catchMouse() {}

private void eatFish() {}

}

public class MainClass{

public static void main(String args[]) {

Dog dog = new Dog(3);

Cat cat = new Cat(4);

if(dogage>catage) {

doghappy();

catunhappy();

}else if(dogage<catage) {

dogunhappy();

cathappy();

}else {

doghappy();

cathappy();

}

}

}

//不知是否是楼主想要的

package comdemo;

import javamathBigDecimal;

import javautilRandom;

import javautilScanner;

/

  Java编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目。

  编写一个能够自动生成小朋友算术练习题目的程序。设计一个程序,要求能够随机生成每个题目,并具有以下基本功能:

  (1)要求题目以单项选择题及填空题两种形式出现。

  (2)完成一题后自动判断答案是否正确,分别d出不同的提示,并自动更新成下一题。

  (3)单击“退出”时,汇总本次计算结果,共完成几题,正确率,并给出相应评语。确定后正式退出。

 /

public class publicDemo2 {

public static void main(String[] args) {

Random random = new Random();

StringBuilder stringBuilder = new StringBuilder();

String[] symbol = {"+","-","","/"};

String question_tip = "选择题(除法保留小数点后两位):";

stringBuilderappend(question_tip)append("\n");

Systemoutprintln(question_tip);

int a;

int b;

String f;

String result_str;

for (int i=1;i<11;i++){

a = randomnextInt(50);

b = randomnextInt(50);

f = symbol[randomnextInt(3)];

String question = i+"、"+a+f+b+"=";

Systemoutprintln(question);

stringBuilderappend(question);

Scanner sc = new Scanner(Systemin);

String sc_str = scnext();

if("/"equals(f)){

double scan_value = DoubleparseDouble(sc_str);

double result_value = a / b;

BigDecimal bigDecimal1 = new BigDecimal(scan_value);

scan_value = bigDecimal1setScale(2, BigDecimalROUND_HALF_UP)doubleValue();

BigDecimal bigDecimal2 = new BigDecimal(result_value);

result_value = bigDecimal2setScale(2, BigDecimalROUND_HALF_UP)doubleValue();

result_str = (scan_value==result_value)"回答正确!":"回答错误!";

stringBuilderappend(scan_value)append(";(答案:"+result_value+")"+result_str)append("\n");

}else{

int scan_value = IntegerparseInt(sc_str);

int result_value;

if("+"equals(f)){

result_value = a + b;

}else if("-"equals(f)){

result_value = a - b;

}else if(""equals(f)){

result_value = a  b;

}else{

break;

}

result_str = (scan_value==result_value)"回答正确!":"回答错误!";

stringBuilderappend(scan_value)append(";(答案:"+result_value+")"+result_str)append("\n");

}

}

Systemoutprintln(stringBuildertoString());

}

}

以上就是关于JAVA简答题与编程全部的内容,包括:JAVA简答题与编程、java编程简答题、帮忙编写一个Java程序,大题如下等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/zz/9651508.html

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

发表评论

登录后才能评论

评论列表(0条)

保存