2个回答
展开全部
(1)
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入两个正整数:");
double a = scan.nextDouble();
double b = scan.nextDouble();
System.out.println("a+b=" + (a + b));
System.out.println("a-b=" + (a - b));
System.out.println("a*b=" + (a * b));
System.out.println("a/b=" + (a / b));
}
}
=====================================
测试结果:
请输入两个正整数:
6
3
a+b=9.0
a-b=3.0
a*b=18.0
a/b=2.0
(2)
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入正整数N");
int N = scan.nextInt();
int sum = 1;
for (int i = 1; i <= N; i++) {
sum = sum * i;
}
System.out.println("N! = " + sum);
}
}
=========================================
测试结果:
请输入正整数N
5
N! = 120
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入两个正整数:");
double a = scan.nextDouble();
double b = scan.nextDouble();
System.out.println("a+b=" + (a + b));
System.out.println("a-b=" + (a - b));
System.out.println("a*b=" + (a * b));
System.out.println("a/b=" + (a / b));
}
}
=====================================
测试结果:
请输入两个正整数:
6
3
a+b=9.0
a-b=3.0
a*b=18.0
a/b=2.0
(2)
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入正整数N");
int N = scan.nextInt();
int sum = 1;
for (int i = 1; i <= N; i++) {
sum = sum * i;
}
System.out.println("N! = " + sum);
}
}
=========================================
测试结果:
请输入正整数N
5
N! = 120
展开全部
1、
public int add(int a,int b){
return a+b;
}
public int sub(int a,int b){
return a-b;
}
public int mul(int a,int b){
return a*b;
}
public double div(int a,int b){
return a/b;
}
2、
public int fac(int n){
int sum = 1;
while(n!=0){
sum = sum*n;
}
return sum;
}
public int add(int a,int b){
return a+b;
}
public int sub(int a,int b){
return a-b;
}
public int mul(int a,int b){
return a*b;
}
public double div(int a,int b){
return a/b;
}
2、
public int fac(int n){
int sum = 1;
while(n!=0){
sum = sum*n;
}
return sum;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询