Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7953877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:15:38+00:00 2026-06-04T03:15:38+00:00

I am writing an application for an exercise in a course I am doing

  • 0

I am writing an application for an exercise in a course I am doing at tech. It is supposed to instantiate 5 objects of the class Book, which contains data fields for a book’s title, author and number of pages. I am having issues with a for.. loop. It skips a step every time after the first loop and I cannot figure out why. Here is my code

import java.util.*;
public class LibraryBook2
{
    public static void main(String[]args)
{
    String name;
    String author;
    int pages;
    Book[] novel = new Book[5];
    novel[0] = new Book();
    novel[1] = new Book();
    novel[2] = new Book();
    novel[3] = new Book();
    novel[4] = new Book();
    Scanner kb = new Scanner(System.in);
    for (int i = 0; i< novel.length;)
    {   
        System.out.println("Please Enter the books title");
        name = kb.nextLine();
        novel[i].setTitle(name);
        System.out.println("Please enter the books author");
        author = kb.nextLine();
        novel[i].setAuthor(author);
        System.out.println("Please enter the number of pages in this book");
        pages = kb.nextInt();
        novel[i].setPages(pages);
        System.out.println(""+novel[i].title);
        System.out.println(""+novel[i].author);
        System.out.println(""+novel[i].pages);
        ++i;
    }
    for (int x = 0; x<novel.length; x++)
    {
    System.out.print(""+ novel[x].title + "\n" + novel[x].author + "\n" + novel[x].pages);
    }
  }
}

During the first for loop, it loops once, prints the book’s title, author and number of pages I entered, like it should. But the second time, it prints “Please enter the books title” then skips straight to the second println without waiting for input. I am new to arrays of objects, and java in general, so any help is appreciated.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:15:40+00:00Added an answer on June 4, 2026 at 3:15 am

    change the code like this:

    public static void main(String []arg){
        String name;
        String author;
        String pages;
        Book[] novel = new Book[2];
        novel[0] = new Book();
        novel[1] = new Book();
        novel[2] = new Book();
        novel[3] = new Book();
        novel[4] = new Book();
        Scanner kb = new Scanner(System.in);
        for (int i = 0; i< novel.length;)
        {   
            System.out.println("Please Enter the books title");
            name = kb.nextLine();
            novel[i].setTitle(name);
            System.out.println("Please enter the books author");
            author = kb.nextLine();
            novel[i].setAuthor(author);
            System.out.println("Please enter the number of pages in this book");
            pages = kb.nextLine();
            novel[i].setPages(Integer.parseInt(pages));
            System.out.println(""+novel[i].title);
            System.out.println(""+novel[i].author);
            System.out.println(""+novel[i].getPages());
            ++i;
        }
        for (int x = 0; x<novel.length; x++)
        {
        System.out.print(""+ novel[x].title + "\n" + novel[x].author + "\n" + novel[x].pages);
        }
    

    Read the page number as nextLine , instead of integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing Windows application (with Borland C++ Builder), which stores large number of
im writing application on asp mvc. so, i have jQuery tabs on index.aspx, which
I'm writing application, which connects to CRM using CRM SDK 4. In the first
I'm writing application which consists of server side on Google App Engine (Java) and
So. Writing application in C, unix, and i have function, which requests user input
I'm writing application for downloading CSV file from web and inserting data into table
im writing an application that downloads and installs addons for programs which needs to
Iam writing an application which will do Conversion from AVI to MPEG, WMV to
I'm writing an application using the Spring Framework. Description of Exercise: Write a program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.