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;…
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) { 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++;…
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…
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 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("%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…