用java编写程序 在控制台下输入两个整数 计算和差积商 最大值和最小值 并输出
3个回答
展开全部
import java.util.InputMismatchException;
import java.util.Scanner;
public class DigitCalc {
public static void main(String[] args) {
int num1 = 0;
int num2 = 0;
for(int i = 1; i <= 2; i++){
try{
System.out.println("Please input an integer: ");
Scanner scanner = new Scanner(System.in);
if(i == 1){
num1 = scanner.nextInt();
}else{
num2 = scanner.nextInt();
}
}catch(InputMismatchException mismatchExp){
i--;
continue;
}
}
int cha = num1 - num2;
int ji = num1 * num2;
double shang = (double)num1 / num2;
int max = Math.max(num1, num2);
int min = Math.min(num1, num2);
System.out.println("差 is: " + cha);
System.out.println("积 is: " + ji);
System.out.println("商 is: " + shang);
System.out.println("最大值 is: " + max);
System.out.println("最小值 is: " + min);
}
}
-------------
Please input an integer:
aa
Please input an integer:
bb
Please input an integer:
22
Please input an integer:
10
差 is: 12
积 is: 220
商 is: 2.2
最大值 is: 22
最小值 is: 10
import java.util.Scanner;
public class DigitCalc {
public static void main(String[] args) {
int num1 = 0;
int num2 = 0;
for(int i = 1; i <= 2; i++){
try{
System.out.println("Please input an integer: ");
Scanner scanner = new Scanner(System.in);
if(i == 1){
num1 = scanner.nextInt();
}else{
num2 = scanner.nextInt();
}
}catch(InputMismatchException mismatchExp){
i--;
continue;
}
}
int cha = num1 - num2;
int ji = num1 * num2;
double shang = (double)num1 / num2;
int max = Math.max(num1, num2);
int min = Math.min(num1, num2);
System.out.println("差 is: " + cha);
System.out.println("积 is: " + ji);
System.out.println("商 is: " + shang);
System.out.println("最大值 is: " + max);
System.out.println("最小值 is: " + min);
}
}
-------------
Please input an integer:
aa
Please input an integer:
bb
Please input an integer:
22
Please input an integer:
10
差 is: 12
积 is: 220
商 is: 2.2
最大值 is: 22
最小值 is: 10
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.print("请输入第一个整数:");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
System.out.print("请输入第二个整数:");
int b=s.nextInt();
System.out.println(a+b);
}
}
public class Test {
public static void main(String[] args) {
System.out.print("请输入第一个整数:");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
System.out.print("请输入第二个整数:");
int b=s.nextInt();
System.out.println(a+b);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
static int max (inot [] ia){
int max = ia [0];
for (int j = 1; j < ia.length; j++){
if(max < ia [j]){
max = ia [j] ;
}
}
return max ;
}
publc static void mian(String [] args){
int [] ia = {8,9};
int m = max (ia);
System.out.println(m);
}
这是最大值,其他的差不多!
int max = ia [0];
for (int j = 1; j < ia.length; j++){
if(max < ia [j]){
max = ia [j] ;
}
}
return max ;
}
publc static void mian(String [] args){
int [] ia = {8,9};
int m = max (ia);
System.out.println(m);
}
这是最大值,其他的差不多!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询