初学java,基础差,麻烦高手写一下代码,参考一下,谢谢了。如图第二题。
答案:2 悬赏:0 手机版
解决时间 2021-02-09 20:53
- 提问者网友:趣果有间
- 2021-02-09 06:12
初学java,基础差,麻烦高手写一下代码,参考一下,谢谢了。如图第二题。
最佳答案
- 五星知识达人网友:时间的尘埃
- 2021-02-09 06:36
import java.util.Scanner;
class Ca{
private double a;
private double b;
public double add(double a, double b){
return a + b;
}
public double jian(double a, double b){
return a - b;
}
public double chen(double a, double b){
return a * b;
}
public double chu(double a, double b){
if(b == 0){
System.out.println("除数不能为0");
return (Double) null;
}else{
return a / b;
}
}
}
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入第一个数:");
double a = sc.nextDouble();
System.out.println("输入第二个数:");
double b = sc.nextDouble();
System.out.println("两个数的和 : " + new Ca().add(a, b));
System.out.println("两个数的差 : " + new Ca().jian(a, b));
System.out.println("两个数的积 : " + new Ca().chen(a, b));
System.out.println("两个数的商 : " + new Ca().chu(a, b));
}
}
追问帮忙做下这题,谢谢了。
class Ca{
private double a;
private double b;
public double add(double a, double b){
return a + b;
}
public double jian(double a, double b){
return a - b;
}
public double chen(double a, double b){
return a * b;
}
public double chu(double a, double b){
if(b == 0){
System.out.println("除数不能为0");
return (Double) null;
}else{
return a / b;
}
}
}
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入第一个数:");
double a = sc.nextDouble();
System.out.println("输入第二个数:");
double b = sc.nextDouble();
System.out.println("两个数的和 : " + new Ca().add(a, b));
System.out.println("两个数的差 : " + new Ca().jian(a, b));
System.out.println("两个数的积 : " + new Ca().chen(a, b));
System.out.println("两个数的商 : " + new Ca().chu(a, b));
}
}
追问帮忙做下这题,谢谢了。
全部回答
- 1楼网友:雪起风沙痕
- 2021-02-09 07:20
package baiqianbaiji;
import java.util.Scanner;
public class baiqianbaiji
{
@SuppressWarnings("resource")
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("请输入连个数");
double a = s.nextDouble();
double b = s.nextDouble();
Cal cal = new Cal();
cal.jia(a,b);
cal.jian(a, b );
cal.cheng(a, b);
cal.chu(a, b);
}
static class Cal
{
public void jia(double i ,double j)
{
System.out.println(i+"+"+j +"=" +(i+j));
}
public void jian(double i ,double j)
{
System.out.println(i+"-"+j+"="+(i-j));
}
public void cheng(double i ,double j)
{
System.out.println(i+"*"+j+"="+(i*j));
}
public void chu(double i ,double j)
{
System.out.println(i+"/"+j+"="+(i/j));
}
}
}
import java.util.Scanner;
public class baiqianbaiji
{
@SuppressWarnings("resource")
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("请输入连个数");
double a = s.nextDouble();
double b = s.nextDouble();
Cal cal = new Cal();
cal.jia(a,b);
cal.jian(a, b );
cal.cheng(a, b);
cal.chu(a, b);
}
static class Cal
{
public void jia(double i ,double j)
{
System.out.println(i+"+"+j +"=" +(i+j));
}
public void jian(double i ,double j)
{
System.out.println(i+"-"+j+"="+(i-j));
}
public void cheng(double i ,double j)
{
System.out.println(i+"*"+j+"="+(i*j));
}
public void chu(double i ,double j)
{
System.out.println(i+"/"+j+"="+(i/j));
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯