JAVA语言程序设计题请高手回答

作者&投稿:大宜 (若有异议请与网页底部的电邮联系)
Java语言程序设计题。求高手帮忙。~

答案依次是
1(1)15 (2)48 (3)45 (4)6.5
2(1)false (2)false (3)true (4)true

public class Main {public static void main(String[] args) throws Exception {Circle c1 = new Circle();c1.setRadius(5);Circle c2 = new Circle(8);int compareResult = compareCircle(c1, c2);if (compareResult > 0) {System.out.println("c1 比 c2 大");} else if (compareResult c2.getRadius()) { // c1半径大于c2return 1;} else if (c1.getRadius() < c2.getRadius()) { // c1半径小于c2return -1;}return 0; // c1半径等于c2}}class Circle {private double radius;public Circle() {}public Circle(double radius) {this.radius = radius;}public double getRadius() {return radius;}public void setRadius(double radius) {this.radius = radius;}}运行结果:

完整代码如下:

public class Complex {

private float real; //实部
private float imagin;//虚部

public Complex(){//无参默认为(0, 2)
this.real = 0F;
this.imagin = 2F;
}

public String toString(){//以a+bi的形式输出的复数
return real + "+" + imagin + "i";
}

// a+ bi + (c+ di) = (a+c) + (b+d)i
public static Complex add(Complex c1, Complex c2){//两个复数相加
Complex complex = new Complex();
complex.setReal(c1.getReal() + c2.getReal());
complex.setImagin(c1.getImagin() + c2.getImagin());

return complex;
}

// a+ bi ==? c + di----> a==c, b==d --> it's true
public static boolean equal(Complex c1, Complex c2){//比较两个复数是否相等
return c1.getReal() == c2.getReal() && c1.getImagin() == c2.getImagin();
}

//a + bi + f = (a+f) + bi
public static Complex addFloat(Complex c1, float fValue){//复数加一浮点数
c1.setReal(c1.getReal() + fValue);
return c1;
}

public float getImagin() {
return imagin;
}

public void setImagin(float imagin) {
this.imagin = imagin;
}

public float getReal() {
return real;
}

public void setReal(float real) {
this.real = real;
}

}

//boss Wang
package example;

public class ComplexClass {
private double real,imag;
public ComplexClass()
{
this.real = 0.0;
this.imag = 0.0;
}
public ComplexClass(double real,double imag)
{
this.real = real;
this.imag = imag;
}
public void setomplex(double real,double imag)
{
this.real = real;
this.imag = imag;
}
public void complexAdd(ComplexClass complex)
{
ComplexClass add = new ComplexClass();
add.real = (this.real + complex.real);
add.imag = (this.imag + complex.imag);
System.out.println(this.toString()+" 和 "+complex.toString()+" 的和是 "+add.toString());
}
public void complexdecrease(ComplexClass complex)
{
ComplexClass dec = new ComplexClass();
dec.real = (this.real - complex.real);
dec.imag = (this.imag - complex.imag);
System.out.println(this.toString()+" 和 "+complex.toString()+" 的差是 "+dec.toString());
}
public void complexCompare(ComplexClass complex)
{
ComplexClass max;
if(this.real == complex.real&&this.imag == complex.imag)
System.out.println(this.toString()+" 和 "+complex.toString()+" 一样大!!!");
if(this.real > complex.real)
System.out.println(this.toString()+" 和 "+complex.toString()+" 中 "+this.toString()+" 大!!!");
if(this.imag > complex.imag)
System.out.println(this.toString()+" 和 "+complex.toString()+" 中 "+this.toString()+" 大!!!");
else
System.out.println(this.toString()+" 和 "+complex.toString()+" 中 "+complex.toString()+" 大!!!");
}
public String toString()
{
String complexString;
if(this.imag == 0)
complexString = String.valueOf(this.real);
else if(this.real == 0)
complexString = String.valueOf(this.imag+"i");
else if(this.imag > 0)
complexString = String.valueOf(this.real + "+" + this.imag + "i");
else
complexString = String.valueOf(String.valueOf(this.real) + this.imag + "i");
return complexString;
}
}

//boss Wang
package example;

public class test {

public static void main(String[] args) {
ComplexClass a = new ComplexClass(1,2);
ComplexClass b = new ComplexClass(2,3);
a.toString();
b.toString();
a.complexAdd(b);
a.complexdecrease(b);
a.complexCompare(b);
}
}
我懒得改;
自己去改改 不难 大体都在 这是我学的时候编的

public class Plural{
private float real;
private float virtual;

//无参构造函数
Plural(){
real=0f;
virtual=0f;
}

Plural(float r,float v){
real=r;
virtual=v;
}
//返回以a+bi的形式输出的复数
String toString(){
return real+"+"+virtual+"i";
}

//与另一个复数相加
void add(Plural p){
real+=p.real;
virtual+=p.virtual;
}
//与一个浮点数相加
void add(float a){
real+=a;
}
//比较两个复数是否相等
boolean equals(Plural p){
return real==p.real&&virtual==p.virtual;
}
}

一、填空
1.方法名;参数列表;个数;类型;顺序
2.this
3.值传递
4.软件重用;程序结构;类;类
5.InpitStreamReader;OutputStreamWriter
6.几个程序或任务的能力

二、选择
A B A D D B C B D A C C

三、判断
1.2.3.7错,其余对

四、
通过按钮激活change()文件。
<Form>
<Input type="button"Value=""onClick="change()">
</Form>

这么简单的题目还要高手回答!
随便一个菜鸟都能回答。
百度知道成了帮学生做作业的地方了么?悲哀!

java程序设计题,帮帮忙给做做看,要一定正确啊,教别人呢,别误人子弟啊...
答:1. Java源程序编译后会生成一种扩展名为(.class)的字节码文件。2. Java小程序不能单独运行,必须将编译后的文件嵌入到网页中,将其嵌 入时使用的标记是(applet)标记。3.若希望所有的控件在界面上从左至右排列,应采用(FlowLayout)布局,设置布局调用的方法是(setLayout)。4.若类中定义的成员...

求高手做一套javar题(全部是选择)
答:1.在JDK环境下编译Java源程序使用的命令是()。A.javaB.javacC.jvmD.tomcat2.Java平台无关性是通过()实现的。A.Java虚拟机B.Java的编辑环境C.Windows操作系统D.UNIX操作系统3... 1.在JDK环境下编译Java源程序使用的命令是( )。A.java B.javacC.jvm D.tomcat 2. Java平台无关性是通过( )实现的。 A...

请高手帮忙解决一些JAVA试题
答:《Java程序设计》期未考试复习题 一.填空 1.在一个java源程序中定义了3个类和15个方法,编译该Java源文件时,会产生个字节码文件,其扩展名是class。2.创建类的关键字是public class.3. 类包声明的关键字是package.4.引用类包的关键字是import.5.声明接口的关键字是interface.6.继承的关键...

一些Java题 求高手解答
答:A) '|' B) '\' C) "\n" D) '我'18、若以下变量均已正确定义并赋值,下面符合Java语言语法的语句是(a )。A) b = a!=7 ; B) a = 7 + b + c=9;C) i=12.3* % 4; D) a = a + 7 = c + b;19、执行下列程序段后,b, x, y的值分别是( b)。int x=6,y=8;...

求高手帮忙编JAVA的程序
答:第一个类:Car.java package test.car;/ 车类 author qinghua9 抽像类,定义两个方法 / public abstract class Car { public void driver(){};public void stop(){};} 第二个类Bus.java package test.car;/ 公共汽车类 author qinghua9 / public class Bus extends Car { public Bus() {...

这道JAVA程序怎么写,请各位大侠帮助
答:import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JApplet;import javax.swing.JButton;import javax.swing.JLabel;public class SimApp extends JApplet implements ActionListener{ private JLabel text = new JLabel();private JButton...

JAVA程序设计课程作业,请高手帮忙啊
答:10.BCD 这题出得真烂,也不给出是哪里定义的paint()方法,这里姑且当做Swing中的一个方法来对待。。以下是判断题:1.A java只支持单继承 2.A 高级的异常类放前面,后面的将无用 3.A 浮点数也可以 4.B 5.A 区分 6.A 抽象类不一定要有抽象方法 7.B 都转为数据类型最大的那个类型再运算 ...

java程序设计小题目求解答
答:1:可独立执行的程序和嵌入式应用程序,前者可独立运行,后者需必须依附在其它程序里执行 2:简单,完全面向对象,可靠,安全,分布式,多线程,平台无关 3:break语句直接跳出整个循环,continue语句只跳出本次循环 4:实例变量属于某个对象的属性,必须创建了实例对象,其中的实例变量才会被分配空间,才能...

高一会考很简单的JAVA语言编程,求大神帮忙!!!给经验。。一共10题,求...
答:public static void main(String[] args) {int sum=0;int k=0;for(int i=1;i<=100;i++){k = i*(100-i);sum=sum+k;}System.err.println(sum);} 第六题 public static void main(String[] args) {System.out.println("种数="+pay(100,0));} private static final int LEN =...

Java程序设计.在线等,求高手帮忙.
答:新建一个Student.java类,代码如下:public class Student { // 注册号、姓名、数学、外语、计算机课程成绩 private String id;private String name;private Integer maths;private Integer english;private Integer computer;public Student() { } public Student(String id, String name, Integer maths, ...