Pattern.java - import java.util.Scanner public class Pattern public static void main(String args final int NUMBER_OF_PENTAGONALS = 100 Display the first

Pattern.java - import java.util.Scanner public class...

This preview shows page 1 - 3 out of 3 pages.

import java.util.Scanner; public class Pattern { public static void main(String[] args) { final int NUMBER_OF_PENTAGONALS = 100; // Display the first 100 pentagonals final int NUMBER_PER_LINE = 10; // Display 10 number per line // Display the first 100 pentagol numbers System.out.println("The first 100 pentagonal numbers, ten per line: "); for (int i = 1; i <= NUMBER_OF_PENTAGONALS; i++) { // Print ten numbers per line if (i % NUMBER_PER_LINE == 0) System.out.printf("%7d\n", getPentagonalNumber(i)); else System.out.printf("%7d", getPentagonalNumber(i)); } } /** Return a pentagonal number */ public static int getPentagonalNumber(int n) { return (n * (3 * n - 1)) / 2; } } // public static void main(String[] args) { // int rows =5; // for (int i = 1; i <= rows; i++) { // for (int j = 1; j <= (i*2-1); j++) { // System.out.print(j); // } // System.out.println(); // } // } //} // Scanner input=new Scanner(System.in); // int rows =input.nextInt(); // for (int i = 0; i < rows; i++) { // for (int k = 1; k <= rows - i; k++) { // System.out.print(" "); // } // for (int j = 1; j <= 2 * i - 1; j++) { // System.out.print("*"); // } // System.out.println(); // // } // for (int i = rows; i > 0; i--) { // for (int k = 1; k <= rows - i; k++) {
Image of page 1
// System.out.print(" "); // } // for (int j = 1; j <= 2 * i - 1; j++) { // System.out.print("*"); // } // System.out.println(); // } // } //} //------------------------------------------------------- //
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Spring '17
  • Ijlal

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture