HW5.2】的更多相关文章

import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of sides: "); int n = input.nextInt(); System.out.print("Enter the length…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the length of side: "); double side = input.nextDouble(); input.close(); System.out.printl…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the year: "); int year = input.nextInt(); input.close(); for(int i = 1; i <= 12; i++) S…
import java.util.Calendar; public class Solution { public static void main(String[] args) { long totalMillis = System.currentTimeMillis(); long totalSeconds = totalMillis / 1000; long second = totalSeconds % 60; long totalMinutes = totalSeconds / 60;…
public class Solution { public static void main(String[] args) { int n1 = (int)(Math.random() * 5 + 1); int n2 = (int)(Math.random() * 5 + 1); int winCount = 0; for(int i = 0; i < 10000; i++) { if(diceGame(n1, n2)) winCount++; n1 = (int)(Math.random(…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an ID number: "); long id = input.nextLong(); input.close(); System.out.println(isValid(id…
public class Solution { public static void main(String[] args) { for(int i = 3; i <= 1000; i++) if(isDoublePrime(i)) System.out.println("(" + i + ", " + (i + 2) + ")"); } public static boolean isDoublePrime(int n) { if(isP…
public class Solution { public static void main(String[] args) { int n1 = (int)(Math.random() * 5 + 1); int n2 = (int)(Math.random() * 5 + 1); diceGame(n1, n2); } public static void diceGame(int n1, int n2) { if(n1 + n2 == 2 || n1 + n2 == 3 || n1 + n…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n", "p", "2^p - 1"); for(int i = 2; i <= 31; i++) { if(isPrime((int)getMersenne(i))) System.out.printf("%d\t%d\n", i, (in…
public class Solution { public static void main(String[] args) { int totalCount = 0; int lineCount = 0; int i = 2; while(true) { if(isPrime(i) && (isPrime(getReverse(i)))) { System.out.printf("%d\t", i); totalCount++; lineCount++; } i++;…
public class Solution { public static void main(String[] args) { int totalCount = 0; int lineCount = 0; int i = 2; while(true) { if(isPrime(i) && isPalindrome(i)) { System.out.print(i + " "); totalCount++; lineCount++; } i++; if(lineCoun…
public class Solution { public static void main(String[] args) { System.out.println(convertMillis(5500)); System.out.println(convertMillis(100000)); System.out.println(convertMillis(555550000)); } public static String convertMillis(long millis) { lon…
import java.util.Calendar; public class Solution { public static void main(String[] args) { System.out.println(getCurrentTime()); } public static String getCurrentTime() { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.Y…
public class Solution { public static void main(String[] args) { int count = 0; for(int i = 0; i < 100; i++) { System.out.print(getRandomChar('A', 'Z') + " "); count++; if(count == 10) { count = 0; System.out.println(); } } count = 0; for(int…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number to calculate the sqrt: "); double number = input.nextDouble(); input.close(); Sys…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); double[] array = new double[10]; System.out.print("Enter 10 numbers: "); for(int i = 0; i < array.length; i++)…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\t%s\n", "ANGLE", "SIN", "COS"); for(int i = 0; i <= 360; i += 10) System.out.printf("%d\t%.4f\t%.4f\n", i, Math…
public class MyTriangle { public static boolean isValid(double side1, double side2, double side3) { if((side1 + side2 > side3) && (side2 + side3 > side1) && (side1 + side3 > side2)) return true; else return false; } public static…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n", "Number", "Sqrt"); for(int i = 0; i <= 20; i++) System.out.printf("%d\t%f\n", i, Math.sqrt(i)); } }…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number: "); int number = input.nextInt(); input.close(); printMatrix(number); } public s…
public class Solution { public static void main(String[] args) { for(int i = 2000; i <= 2010; i++) System.out.printf("%d\t%d\n", i, numberOfDaysInAYear(i)); } public static int numberOfDaysInAYear(int year) { if((year % 4 == 0 && year…
public class Solution { public static void main(String[] args) { System.out.printf("%10s\t%10s\t%10s\t%10s\t%10s\n", "Taxable", "Single", "Married", "Married", "Head of"); System.out.printf("…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n", "i", "m(i)"); for(int i = 10; i <= 100; i += 10) System.out.printf("%d\t%f\n", i, getMi(i * 1.0)); } public static do…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n", "i", "m(i)"); for(int i = 1; i <= 20; i++) System.out.printf("%d\t%f\n", i, getMi(1.0 * i)); } public static double g…
public class Solution { public static void main(String[] args) { printChars('1', 'Z', 10); } public static void printChars(char ch1, char ch2, int numberPerLine) { int count = 0; int start = (int)ch1; int end = (int)ch2; for(int i = start; i <= end;…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\n", "Sales", "Prize"); for(int i = 10000; i <= 100000; i += 5000) System.out.printf("%d\t%f\n", i, computeCommission(i *…
public class Solution { public static void main(String[] args) { int count = 0; for(int i = 1; i < 10000; i++) if(isPrime(i)) count++; System.out.println("The count of the prime number smaller than 10000 is: " + count); } public static boolea…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\t%s\t%s\n", "Inch", "Meter", "Meter", "Inch"); for(double i = 1, j = 20; i <= 10 && j <= 65; i++, j…
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\t%s\t%s\n", "Celsius", "Fahrenheit", "Fahrenheit", "Celsius"); for(double i = 40, j = 120; i >= 31 && j…
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("The amount invested: "); double investAmount = input.nextDouble(); System.out.print("Annual…