本文共 3257 字,大约阅读时间需要 10 分钟。
本题目要求读入2个整数A和B,然后输出两个数的最大值。
输入在一行中给出2个绝对值不超过1000的整数A和B。
对每一组输入,在一行中输出最大值。
18 -299
18
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int x= sc.nextInt(); int y= sc.nextInt(); int z=x>y?x:y; System.out.println(z); }}
统计1…n的闭区间中,能够被3整除元素的奇数和偶数的个数
输入值n的范围是 【1…1000】
奇数个数,偶数个数
5
1,0
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(); int x=0,y=0; for(int i=1;i<=n;i++){ if(i%3==0){ if(i%2==0){ y++; } else{ x++; } } } System.out.println(x+","+y); }}
What is the time difference between 10:30 and 11:45?
Your program reads two time spots and prints the time difference between them, in terms of hours and minutes.
Two time spots, in 24-hour, each is represented as two numbers, as “hour minute”. The second time spot is later than the first and both are within the same day.
Two numbers represent the time difference. The first is the hours in the difference, while the second is the minutes.
10 30 11 45
1 15
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h1 = sc.nextInt(); int m1 = sc.nextInt(); int h2 = sc.nextInt(); int m2 = sc.nextInt(); int h,m; if(m2>=m1){ h=h2-h1; m=m2-m1; } else{ h=h2-1-h1; m=m2+60-m1; } System.out.println(h + " " + m); }}
输入2个整数,输出它们的和、差、乘积和准确的商。
输入两个整数
每一行中依次输出四则运算的结果
7016
865411204.375
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m= sc.nextInt(); int n= sc.nextInt(); int a=m+n; int b=m-n; int c=m*n; double d=(double)m/(double)n; System.out.println(a); System.out.println(b); System.out.println(c); System.out.printf("%.3f",d); }}
计算两个数的和。 通过键盘为变量a和b赋值,然后计算变量a与b的和,并将和赋值给变量sum,最终输出变量sum的值;
输入两个整数
两个数的和
2 8
10
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m= sc.nextInt(); int n= sc.nextInt(); System.out.println(m+n); }}
求一个三位正整数各位数字之和
输入一个三位的正整数
输出百十个位上各位数字的和
678
21
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m= sc.nextInt(); int a=m/100; int b=m%100/10; int c=m%10; System.out.println(a+b+c); }}
转载地址:http://ijnlf.baihongyu.com/