#Java# SDKD 软件18-1,3 实验1
发布时间:2020-12-15 07:50:31 所属栏目:Java 来源:网络整理
导读:求最大值 考点 基本输入输出,分支语句(if-else) 代码 import java.io.*;import java.util.*;public class Main { public static void main(String[] args) { int a,b; Scanner cin = new Scanner(System.in); a = cin.nextInt(); b = cin.nextInt(); System
求最大值考点基本输入输出,分支语句(if-else) 代码import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { int a,b; Scanner cin = new Scanner(System.in); a = cin.nextInt(); b = cin.nextInt(); System.out.println(a >= b ? a : b); } } 判断闰年考点基本输入输出,分支语句(if-else) 代码import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { int year; Scanner cin = new Scanner(System.in); year = cin.nextInt(); boolean yes = false; if (year % 400 == 0) yes = true; else if (year % 4 == 0 && year % 100 != 0) yes = true; System.out.println(yes ? "yes" : "no"); } } 水仙花数考点基本输入输出,分支语句(if-else),循环语句 代码打表法 import java.io.*; import java.util.*; public class Main { static final Scanner cin = new Scanner(System.in); public static void main(String[] args) { int[][] ans = new int[5][]; ans[0] = new int[] { 153,370,371,407 }; ans[1] = new int[] { 1634,8208,9474 }; ans[2] = new int[] { 54748,92727,93084 }; ans[3] = new int[] { 548834 }; ans[4] = new int[] { 1741725,4210818,9800817,9926315 }; int n = cin.nextInt() - 3; for (int i = 0; i < ans[n].length; i++) { System.out.println(ans[n][i]); } } } 循环法 import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); long N = cin.nextLong(); long _start = 1; for (long i = 0; i < N - 1; i++) _start *= 10; long _end = _start * 10 - 1; for (long i = _start; i <= _end; i++) { long tmp = 0,cur = i; while (true) { if (cur == 0) break; long m = cur % 10,ans = 1; for (int j = 0; j < N; j++) ans *= m; tmp += ans; cur /= 10; } if (tmp == i) System.out.println(tmp); } } } 基本输入考点基本输入输出 代码import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) //还有下一个输入 { int a = cin.nextInt(); int b = cin.nextInt(); System.out.println(a+b); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |