Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 6, Problem 6.1PE
Expert Solution & Answer
Check Mark
Program Plan Intro

Program Plan:

  • Declare the class “Penta”
  • Definition for main class
    • Use for loop to iterate the variable “j” equals to “100”.
    • Check whether “j” mod “10” equals to 0.
      • Call the method “getPentagonalNumber()”.
    • Otherwise, call the method “getPentagonalNumber()” concatenate with space.
  • Method definition for “getPentagonalNumber()”
    • Return “n * (3 * n - 1) / 2”.
Program Description Answer

Program to display first 100 pentagonal numbers with 10 numbers on each line using the method “getPentagonalNumber ()”

Explanation of Solution

Program:

//Definition for class "Penta"

public class Penta

{

//Definition for main class

public static void main(String[] args)

{

//For loop to iterate the variable

for (int j = 1; j <= 100; j++)

//Check whether the variable "j" mod 10 equals to "0"

if (j % 10 == 0)

//Call the method "getPentagonalNumber"

System.out.println(getPentagonalNumber(j));

else

//Call the method "getPentagonalNumber"

System.out.print(getPentagonalNumber(j) + " ");

}

//Method definition for "getPentagonalNumber"

public static int getPentagonalNumber(int n)

{

//Return the result

return n * (3 * n - 1) / 2;

}

}

Sample Output

1 5 12 22 35 51 70 92 117 145

176 210 247 287 330 376 425 477 532 590

651 715 782 852 925 1001 1080 1162 1247 1335

1426 1520 1617 1717 1820 1926 2035 2147 2262 2380

2501 2625 2752 2882 3015 3151 3290 3432 3577 3725

3876 4030 4187 4347 4510 4676 4845 5017 5192 5370

5551 5735 5922 6112 6305 6501 6700 6902 7107 7315

7526 7740 7957 8177 8400 8626 8855 9087 9322 9560

9801 10045 10292 10542 10795 11051 11310 11572 11837 12105

12376 12650 12927 13207 13490 13776 14065 14357 14652 14950

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Need Java method please. Thank you.
Need Java method please. Thank you.
3. Write two nested loops to generate the following output. (Note: There is one space between each number, and any extra line shown is intentional.) 12 10 8 6 18 15 12 24 20 30 2 3 3 6 48 12 5 10 15 20 6 12 18 24 30

Chapter 6 Solutions

Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY