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

  • SEARCH
  • Home
  • 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 8563841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:03:32+00:00 2026-06-11T17:03:32+00:00

My assignment calls for the line number to be display with the output. The

  • 0

My assignment calls for the line number to be display with the output. The professor suggested I do it with a counter and as seeing Java doesn’t have an easy way to print out the current line number, I just created a counter as suggested. The below code is as follows:

  //Count Increment
    for (count = 1; count<= 5; count++)
    {

    }   

    //Display information
    System.out.println(count + "." + " " + "Street:"+ " " + streetName + " " +  "#" + streetNumber);
    System.out.println(count + "." + " " + "Total Rooms:"+ " " + numofRooms);
    System.out.println(count + "." + " " + "Total Area:"+ " " + totalSqFt + " sq.ft");
    System.out.println(count + "." + " " + "The price per Sq. Ft is " + "$" + priceperSqFt);
    System.out.println(count + "." + " " + "The estimated property value is "+ "$" + estimatedPropertyvalue);

However, the output starts the line counter at six as demonstrated here:

6. Street: park avenue #44
6. Total Rooms: 5
6. Total Area: 2500.0 sq.ft
6. The price per Sq. Ft is $120.4
6. The estimated property value is $301000.0

Removing the brackets doesn’t help either. How can I get the line count to correctly state 1,2,3,4,5?

Please ask for clarification if needed!! Thanks.

  • 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-11T17:03:34+00:00Added an answer on June 11, 2026 at 5:03 pm

    Your prints are outside of the for loop. Your for loop ends when the counter is “6” which is when it exits the for loop. This variable doesn’t change so the current value is “6”,that is why it always prints “6” below on your code. If you want to print the line number for each instruction you could do something like this:

            count = 0;
            System.out.println(++count + "." + " " + "Street:"+ " " + streetName + " " +  "#" + streetNumber);
    

    “++count”, you increment the variable the moment you write a line, in the first case it should print 1 then 2 etc. Hope this helped 🙂

    The loop is not required cause you are only counting the lines one time each. If you put those lines in a loop that goes from 0 to 5 you will be counting each line 5 times. Since you only need to count each line ONE time you dont need the loop and just the simple increment I previously mentioned. Hope this clears out why the loop is not required

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

Sidebar

Related Questions

I am doing a batch scripting assignment where I have to call one script
My assignment requires that I have an ER diagram that shows the dependencies between
I have a large text file I need to sort in Java. The format
I have read Java String class is immutable and thread-safe but I am still
I have been working on and off on an assignment for my C class
I posted a question earlier for a homework assignment but I have a new
I'm working on an assignment, and my professor has given us the function prototypes
I am doing a homework assignment that reads in a book. First, a line
so, I have an assignment for my Operating Systems class wherein i am to
I'm having trouble resolving a CCE. This assignment calls for the user to open

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.