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 8744811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:54:10+00:00 2026-06-13T11:54:10+00:00

I’m just wondering is there a way to make the ‘null’ that is outputted

  • 0

I’m just wondering is there a way to make the ‘null’ that is outputted when using a for loop output white space?

For example, I have a 2d array of an type object and when displaying the array I want to display the first three elements and then skip say 10 empty spaces then print another three elements.

Also if I was to use a random generator to pick array elements at random would the empty elements affect this or not?

Main:

public class CinemaSystem {

    public static void main(String[] args) {
        Seat cinemaactual = new Seat("Cinema");
        Seat[][] cinema = new Seat[12][23];

        Ticket ticket = new Ticket();
        Scanner scan = new Scanner(System.in);
        String answer, contiune;

        int number, check = 0, category, id;

        do {
            System.out.print("Welcome to the Theatre Booking System. (QUIT to exit)"
                    + "\nWould you like to purchase tickets or list available seats?"
                    + "(/Purchase/List/Help)");
            answer = scan.nextLine();

            if (answer.equalsIgnoreCase("purchase")) {
                do {

                    System.out.println("Please choose the cateogry of ticket "
                            + "you would like, followed by who the ticket is for"
                            + "and the amount required. (separated by a space)\n"
                            + "1. Gold\n2. Silver\n3. Bronze\n\n1. Adult\n2."
                            + " Child\n3. Concession");
                    category = scan.nextInt();
                    number = scan.nextInt();
                    id = scan.nextInt();
                    if (category == 1 || category == 2 || category == 3 && id == 1 || id == 2 || id == 3) {
                        ticket.SetType(category);
                        if (category == 1) {
                            ticket.SetName("Gold");
                        } else if (category == 2) {
                            ticket.SetName("Siler");
                        } else {
                            ticket.SetName("Bronze");
                        }
                        ticket.SetNumber(number);
                        ticket.SetID(id);
                        if (id == 1) {
                            ticket.SetCategory("Adult");
                        } else if (id == 2) {
                            ticket.SetCategory("Child");
                        } else {
                            ticket.SetCategory("Bronze");
                        }
                        System.out.print("You have selected"
                                + ticket.GetNumber() + " " + ticket.GetName()
                                + " ticket(s) at the" + ticket.GetCategory() + " price .");

                        ticket.BuyTicket(category, id, number);
                    } else {
                        System.out.print("Sorry, incorrect input, please enter an apropriate value.");
                        check = scan.nextInt();
                    }
                } while (check == 0 || check > 3);

                do {
                    System.out.print("Would you like to perchase more tickets? (Yes/No)");
                    contiune = scan.nextLine();
                } while (contiune.equalsIgnoreCase("Yes"));
            } else if (answer.equalsIgnoreCase("list")) {
                cinemaactual.CreateTheatre(cinema);
                cinemaactual.DisplayTheatre(cinema);
            } else if (answer.equalsIgnoreCase("help")) {
                // Code for help
            } else if (answer.equalsIgnoreCase("quit")) {
                System.exit(-1);
            }

            System.out.print("Sorry, incorrect input please enter"
                    + " a valid input (Purchase/List/Help or QUIT to exit");
            answer = scan.nextLine();

        } while (!answer.equalsIgnoreCase("purchase")
                || !answer.equalsIgnoreCase("List")
                || !answer.equalsIgnoreCase("help")
                || !answer.equalsIgnoreCase("quit"));
    }
}

Method in the class that makes the array:

public Seat[][] CreateTheatre(Seat[][] x) {
for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 4; col++) {
        x[row][col] = new Seat("B");
    }
}

for (int row = 8; row < 12; row++) {
    for (int col = 0; col < 4; col++) {
        x[row][col] = new Seat("S");
    }
}

for (int row = 0; row < 8; row++) {
    for (int col = 19; col < 23; col++) {
        x[row][col] = new Seat("B");
    }
}

for (int row = 8; row <12; row++){
    for (int col = 19; col < 23; col++) {
        x[row][col] = new Seat("S");
    }
}

for (int row = 3; row < 5; row++) {
    for (int col = 4; col < 9; col++) {
        x[row][col] = new Seat("B");
    }
}

for (int row = 3; row < 5;row++){
    for (int col = 14; col < 19; col++) {
        x[row][col] = new Seat("S");
    }
}

for (int row = 9; row < 12; row++) {
    for (int col = 7; col < 4; col++) {
        x[row][col] = new Seat("S");
    }
}

for (int row = 3; row < 5; row++) {
    for (int col = 14; col < 20; col++) {
        x[row][col] = new Seat("B");
    }
}

for (int row = 5; row < 9; row++) {
        for (int col = 4; col < 9; col++){
        x[row][col] = new Seat("S");
    }
}

for (int row = 5; row < 9; row++) {
    for (int col = 14; col < 20; col++) {
        x[row][col] = new Seat("S");
    }
}

for (int row = 6; row < 9; row++) {
    for (int col = 9; col < 14; col++) {
        x[row][col] = new Seat("G");
    }
}

for (int row = 9; row < 12; row++) {
    for (int col = 7; col < 16; col++) {
        x[row][col] = new Seat("G");
    }
}
return x;
}

For the display of the array:

public void DisplayTheatre(Seat[][] x) {
    for (int row = 0; row < x.length; row++) {
        for (int col = 0; col < x[row].length; col++) {
            System.out.print(x[row][col] + "  ");
        }
        System.out.println();
    }
}

Just wondering if I can remove the null since I want some objects display then blank space in the middle and then some more, on the same line.

Also do null elements interfere with randomly selecting elements from an array, like will a null element ever be randomly selected?

  • 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-13T11:54:10+00:00Added an answer on June 13, 2026 at 11:54 am

    if i understand your requirement. below is something you are looking for .

      String[] arr = new String[5];
           arr[0]="2";
           arr[1]="3";
           arr[4]="5";
           for(int i=0; i<arr.length; i++){
               if(arr[i]==null){
                   System.out.println(' ');
               }
               else {
                   System.out.println(arr[i]);
               }
           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.