Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: 1000 locker problem

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 1000 locker problem

    there are errors to this java but i dont know where

    import java.util.Random;
    public class LOCKER{
    public static void main(String[] args){
    Scanner keyboard = new Scanner(System.in);
    int studentVisitCount = 0;
    System.out.print("Enter the number of lockers: ");
    int numberOfLockers = console.nextInt();
    for(int x==0 ;x<=numberOfLockers ; x++){
    if(x%y==0){
    studentVisitCount--;
    }
    for(int y=0; y<=x; y++){
    if(studentVisitCount%3!=0){
    System.out.print(y+" ");
    }
    }
    }
    System.out.println("The number of lockers and students are: "+numberOfLockers);
    System.out.print("The locker numbers left open at the end of the game are: ");
    }
    }

    --- Update ---

    A high school has 1000 students and 1000 lockers, one locker for each student. On the first day
    of school, the principal plays the following game: She asks the first student to open all the
    lockers. She then asks the second student to close all the even-numbered lockers. The third
    student is asked to check every third locker. If it is open, the student closes it; if it is closed, the
    student opens it. The fourth student is asked to check every fourth locker. If it is open, the
    student closes it; if it is closed, the student opens it. The remaining students continue this game.
    In general, the nth student checks every nth locker. If it is open, the student closes it; if it is
    closed, the student opens it. After all the students have taken turns, some of the lockers are
    open and some are closed.
    The program below, when ran, will prompt the user to enter the number of lockers in the
    school. After the game is over, the program will output the number of lockers and the lockers
    numbers of the lockers that are open. However, the statements are in the wrong order, and
    there are some bugs in this program. Rearrange the statements and also find and remove the
    bugs so that the program can run properly

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,358
    Thanks
    54
    Thanked 2,636 Times in 2,586 Posts

    Default Re: 1000 locker problem

    there are errors
    Can you make a list of the steps the program should take to solve the problem?
    Given a list of the steps, then go through the code to see if it is doing the right thing in the correct order.
    Add each item in the list of steps as a comment in the code to make it easier to see if the code is correct.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Be sure to fix the code's indentations to make it easier to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: September 28th, 2014, 02:38 PM
  2. how to find all the prime no. in 1000?
    By Billzhang in forum Java Theory & Questions
    Replies: 3
    Last Post: December 5th, 2013, 09:31 AM
  3. [SOLVED] displaying every 1000 comparisons in merge sort
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 27th, 2012, 07:26 PM
  4. Win 1000$ now [Java WebApp]
    By biz in forum Paid Java Projects
    Replies: 3
    Last Post: November 2nd, 2011, 11:05 AM
  5. The sum and product of a positive number between 1000 and 9999.
    By metaleddie13 in forum Member Introductions
    Replies: 1
    Last Post: September 15th, 2011, 04:39 AM

Tags for this Thread