JAVA练习题函数调用
程序员文章站
2024-03-05 14:34:31
...
JAVA练习题函数调用
创建一个类,为该类定义三个构造函数,从键盘输入两个int值,三个double值,两个字符串,分别执行以下操作
import java.util.Scanner;
class Check {
private int a,b;
private double c,d,e;
private String f,g;
public Check(int a,int b,double c,double d,double e,String f,String g){
this.a=a;
this.b=b;
this.c=c;
this.d=d;
this.e=e;
this.f=f;
this.g=g;
}
public void bijiao(){
System.out.println("Larger value: "+Math.max(a,b));
}
public void cheng(){
System.out.println("a*b*c = "+c*d*e);
}
public void deng(){
if(f.equals(g))
System.out.println("Are equal: true");
else
System.out.println("Are equal: false");
}
}
public class Main {
public static void main(String args[]) {
Scanner ch=new Scanner(System.in);
int a=ch.nextInt();
int b=ch.nextInt();
double c=ch.nextDouble();
double d=ch.nextDouble();
double e=ch.nextDouble();
String f=ch.next();
String g=ch.next();
Check shu=new Check(a,b,c,d,e,f,g);
shu.bijiao();
shu.cheng();
shu.deng();
}
}
上一篇: JQuery入门
下一篇: jquery画图插件jPainter