HW5.1

 1 public class Solution
 2 {
 3     public static void main(String[] args)
 4     {
 5         int count = 0;
 6
 7         for(int i = 1; i <= 100; i++)
 8         {
 9             System.out.print(getPentagonalNumber(i) + " ");
10             count++;
11
12             if(count == 10)
13             {
14                 System.out.println();
15                 count = 0;
16             }
17         }
18     }
19
20     public static int getPentagonalNumber(int n)
21     { return n * (3 * n - 2) / 2; }
22 }
时间: 2024-10-10 04:12:11

HW5.1的相关文章

HW5.14

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 10; i <= 100; i += 10) 8 System.out.printf("%d\t%f\n", i, getMi(i * 1.0)); 9

HW5.2

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the number: "); 9 long number = input.nextLong(); 10 11 input.close(); 12

HW5.13

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\n", "i", "m(i)"); 6 7 for(int i = 1; i <= 20; i++) 8 System.out.printf("%d\t%f\n", i, getMi(1.0 * i)); 9 } 10 1

HW5.10

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int count = 0; 6 7 for(int i = 1; i < 10000; i++) 8 if(isPrime(i)) 9 count++; 10 11 System.out.println("The count of the prime number smaller than 10000 is: " + count)

HW5.30

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 3; i <= 1000; i++) 6 if(isDoublePrime(i)) 7 System.out.println("(" + i + ", " + (i + 2) + ")"); 8 } 9 10 public static boolean isDouble

HW5.4

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 r

HW5.32

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int n1 = (int)(Math.random() * 5 + 1); 6 int n2 = (int)(Math.random() * 5 + 1); 7 int winCount = 0; 8 9 for(int i = 0; i < 10000; i++) 10 { 11 if(diceGame(n1, n2)) 12 winCount

HW5.9

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\t%s\t%s\n", "Inch", "Meter", "Meter", "Inch"); 6 7 for(double i = 1, j = 20; i <= 10 && j <

HW5.3

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a number: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 S