JAVA2. 简单运算
描述
输入两个正整数a和b,输出这两个正整数的和,差,积,商,模(若a>b则输出a-b,a/b,a%b的值反之输出b-a,b/a,b%a的值,不考虑小数,请使用int类型)输入描述
两个正整数输出描述
它们的和,差,积,商,模。每个值之间用空格隔开示例1
输入:
10 5
输出:
15 5 50 2 0
Java 解法, 执行用时: 10ms, 内存消耗: 9408KB, 提交时间: 2022-01-30
/* import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); int b = scanner.nextInt(); scanner.close(); //write your code here...... System.out.printf("%d %d %d %d %d",a+b,a>b?a-b:b-a,a*b,a>b?a/b:b/a,a>b?a%b:b%a); } } */ import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); int a = Integer.parseInt(line[0]), b = Integer.parseInt(line[1]); if(a > b)System.out.print((a+b) + " " + (a-b) + " " + a*b + " " + a/b + " " + a%b); else System.out.print((a+b) + " " + (b-a) + " " + a*b + " " + b/a + " " + b%a); } }
Java 解法, 执行用时: 10ms, 内存消耗: 9432KB, 提交时间: 2022-01-22
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); int a = Integer.parseInt(line[0]), b = Integer.parseInt(line[1]); if(a>0&&b>0){ PrintWriter pw = new PrintWriter(System.out); if(a > b){ pw.print((a+b) + " " + (a-b) + " " + (a*b) + " " + (a/b) + " " + (a%b)); }else{ pw.print((a+b) + " " + (b-a) + " " + (a*b) + " " + (b/a) + " " + (b%a)); } pw.flush(); pw.close(); } } }
Java 解法, 执行用时: 11ms, 内存消耗: 9488KB, 提交时间: 2022-07-14
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; public class Main{ public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); InputStream in = System.in; int c; int num = 0; int a=0,b=0; while (true) { c = in.read(); if (c == 10) { b=num; break; } if(c==32){ a=num; num=0; continue; } num =num*10+ c-48; } if(a > b){ out.print((a+b) + " " + (a-b) + " " + (a*b) + " " + (a/b) + " " + (a%b)); }else{ out.print((a+b) + " " + (b-a) + " " + (a*b) + " " + (b/a) + " " + (b%a)); } out.flush(); out.close(); } }
Java 解法, 执行用时: 12ms, 内存消耗: 9396KB, 提交时间: 2022-06-12
import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String[] num=bf.readLine().split(" "); int a=Integer.valueOf(num[0]); int b=Integer.valueOf(num[1]); if(a<b){ int c=a; a=b; b=c; } System.out.println((a+b) +" " + (a-b) + " "+ a*b +" "+a/b+" "+ a%b); } }
Java 解法, 执行用时: 12ms, 内存消耗: 9428KB, 提交时间: 2022-07-30
import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" ") ; int a = Integer.parseInt(line[0]),b = Integer.parseInt(line[1]); PrintWriter pw = new PrintWriter(System.out); if(a < b){ a^=b; b^=a; a^=b; } pw.print((a+b) + " " + (a-b) + " " + (a*b) + " " + (a/b) + " " + (a%b)); pw.flush(); pw.close(); } }