Advertisement
luliu

MyprogrammingLab 71077

Nov 2nd, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. /*
  2.  * Name: Lu Liu
  3.  * Date: 11/2/2015
  4.  * Course Number: CSC-111
  5.  * Course Name: Introduction to Java Programming
  6.  * Problem Number:MyprogrammingLab 71077
  7.  * Email:lliu0001@student.stcc.edu
  8.  * Problem Description:pentagonal numbers
  9.  */
  10.  
  11. package chapter06;
  12. import java.util.Scanner;
  13. public class PentagonalNumbers {
  14.     public static int getPentagonalNumber(int n) {
  15.         return n * ((3 * n) - 1) / 2;
  16.     }
  17.    
  18.     public static void main(String[] args) {
  19.         Scanner input = new Scanner(System.in);
  20.         System.out.println("Enter an integer for the n pengonal numbers you want displays: ");
  21.         int n = input.nextInt();
  22.         for (int i = 1; i <= n; i++) {
  23.             System.out.print(getPentagonalNumber(i) + " ");
  24.             if (i % 10 == 0)
  25.                 System.out.println();
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement