publicclassMain { publicstaticvoidmain(String[] args){ // write your code here Scannercin=newScanner(System.in);
inta= cin.nextInt(); intb= cin.nextInt(); intc=180 - a -b;
if (a > 0 && b > 0 && c > 0) { if (a + b == 90) { System.out.println("直角三角形"); } elseif (a + b < 90) { //c > 90 System.out.println("钝角三角形"); } else { System.out.println("锐角三角形"); } } else { System.out.println("无法组成三角形"); } } }
2515 · 唯一存在的数字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import java.util.*;
publicclassSolution { /** * @param nums: Represents the incoming number * @return: A int value representing whether the * return is a palindrome or not */ publicintuniqueNumber(int nums[]) { // write your code here intans=0; for(inti=0; i < nums.length; i++){ ans ^= nums[i]; } return ans; } }
classMain { publicstaticvoidmain(String[] args) { // write your code here // read data from console Scannersc=newScanner(System.in); intyear= sc.nextInt(); intmonth= sc.nextInt();
// output the answer to the console according to the // requirements of the question switch (month) { case1: case3: case5: case7: case8: case10: case12: System.out.println("31 days");
publicclassMain { publicstaticvoidmain(String[] args) { // write your code here // read data from console Scanner sc=newScanner(System.in); int n=sc.nextInt(); // output the answer to the console according to the // requirements of the question switch(n/10){ case10: System.out.println("A"); break; case9: System.out.println("A"); break; case8: System.out.println("B"); break; case7: System.out.println("C"); break; case6: System.out.println("D"); break; default: System.out.println("E"); } } }
publicclassMain { publicstaticvoidmain(String[] args) { inta= Integer.parseInt(args[0]); intb= Integer.parseInt(args[1]); // write your code here // please print the greatest common divisor of a and b intres=1; intminval= Math.min(a,b); intmaxVal= Math.max(a,b);
if(maxVal % minval == 0) { System.out.println(minval); return; } while (a % 2 == 0 && b % 2 == 0) { res *= 2; a /= 2; b /= 2; } while (a % 3 == 0 && b % 3== 0) { res *= 3; a /= 3; b /= 3; } while (a%5 ==0 && b%5==0) { res *= 5; a /= 5; b /= 5; } System.out.println(res); } }
2813 · 求 1 — 100 的偶数和
1 2 3 4 5 6 7 8 9 10 11 12 13
publicclassMain { publicstaticvoidmain(String[] args) { // write your code here intres=0; inti=0; while(i <= 100) { res += i; i += 2; } System.out.println("Even sum of 1 - 100: "+res); } }
2259 · 求和(Java 版)
1 2 3 4 5 6 7 8 9 10 11
import java.util.Scanner; publicclassMain { publicstaticvoidmain(String[] args) { // write your code here // read data from console Scannersc=newScanner(System.in); intn= sc.nextInt(); // output the answer to the console according to the requirements of the question System.out.println((1+n)*n/2); } }
publicclassSolution { /** * @param str: Indicates the string passed in * @return: means return the case-converted string */ public String alphabetConversion(String str) { // write your code here Strings=""; for (inti=0; i < str.length(); i++) { charc= str.charAt(i); if (c>='A'&&c<='Z') { c += 32; s += c; }elseif(c>='a'&&c<='z'){ c -= 32; s += c; }elseif(c>='0'&&c<='9'){ s += c; } } return s; } }
2408 · 字符串字符排序
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import java.util.Arrays; publicclassSolution { /** * @param str: Arbitrary non-empty string * @return String in alphabetical ascending order */ public String handle(String str) { // write your code here char[] chars = str.toCharArray(); Arrays.sort(chars); // 将数组转化成字符串 return String.valueOf(chars); } }
2828 · 拼接字符串并改为大写
1 2 3 4 5 6 7 8 9 10
publicclassMain { publicstaticvoidmain(String[] args) { Stringstr1="I love "; Stringstr2="China"; // write your code here str1 = str1.concat(str2); str1 = str1.toUpperCase(); System.out.println(str1); } }
2329 · 求直角坐标系内两点间距离(Java 版)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import java.util.Scanner;
publicclassMain { publicstaticvoidmain(String[] args) { // write your code here // read data from console Scannersc=newScanner(System.in); intx1= sc.nextInt(); inty1= sc.nextInt(); intx2= sc.nextInt(); inty2= sc.nextInt(); // output the answer to the console according to the // requirements of the question doubledistance= Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); System.out.printf("%.2f\n", distance); } }
2283 · 圆型周长(Java 版)
1 2 3 4 5 6 7 8
publicclassMain { publicstaticvoidmain(String[] args) { intr= Integer.parseInt(args[0]); // write your code here // please print the perimeter of the circle System.out.printf("%.2f",2*Math.PI*r); } }
2289 · 字符的ASCII码(Java 版)
1 2 3 4 5 6 7 8 9 10
import java.util.Scanner;
publicclassMain { publicstaticvoidmain(String[] args) { // write your code here Scannerscan=newScanner(System.in); char c= scan.next().charAt(0); System.out.println(c+0); } }
2837 · 复制指定元素
1 2 3 4 5 6 7 8 9 10 11 12
publicclassMain { publicstaticvoidmain(String[] args) { int[] arr={1,2,3,4,5,6,7,8,9}; // write your code here int [] newArr = newint[5];