java编程 在线等,求帮忙

发布网友

我来回答

4个回答

热心网友

//计算第一个问题
import java.util.Scanner;

public class AddSub {
private int a, b;

public AddSub() {
}

public AddSub(int a, int b) {
this.a = a;
this.b = b;
}

public int summation() {
return a + b;
}

public int forPoor() {
return a - b;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
AddSub as = new AddSub(sc.nextInt(), sc.nextInt());
System.out.print(as.summation()+" ");
System.out.println(as.forPoor());
}

}
//计算第二个问题
import java.util.Scanner;

public class JudgeLeap {
private int year;

public JudgeLeap(int year) {
this.year = year;
}

public JudgeLeap() {
}

public Boolean isLeapYear() {
if (year / 100.0 == year / 100) {
if (year % 400 == 0)
return true;
else
return false;
} else {
if (year % 4 == 0)
return true;
else
return false;
}

}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
JudgeLeap jl=new JudgeLeap(sc.nextInt());
System.out.println(jl.isLeapYear());
}
}
//没给注释的

热心网友

第1题:

public class AddSub {
public static void main(String[] args) {
int num1, num2;

if(args.length != 2){
System.out.println("参数数量错误,必须是两个参数");
return;
}
num1 = Integer.parseInt(args[0]);
num2 = Integer.parseInt(args[1]);

System.out.printf("%d %d\n", num1+num2, num1-num2);
}
}

第2题:

public class JudgeLeap {
public static void main(String[] args) {
if(args.length != 1){
System.out.println("参数错误,必须是1个参数");
return;
}

int year = Integer.parseInt(args[0]);

if(year%400==0 || (year%4==0 && year%100!=0))
System.out.println("true");
else
System.out.println("false");
}
}

热心网友

楼上已经给出答案了,大体没什么问题,不过为什么不用IDE?还在用记事本。

热心网友

又是个懒惰的Java初学者,按楼上的做吧

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
1.096806s