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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:34:25+00:00 2026-06-18T05:34:25+00:00

This program works when the int array does not need to count up to

  • 0

This program works when the int array does not need to count up to 10. My problem is that charat is reading 10 as two different chars, which they are. How am i able to make an exception for 10? for example, the program below, when you type in 5 people, the program prints out from 6-1, as the 1 is reading from the first char of 10. When you type in 6, charat is reading the 0, so it prints out 6-0.

package javaapplication2;

import java.util.*;

public class JavaApplication2 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the amount of people in your group, up to 6");
        int num = input.nextInt();

        if (num > 6) {
            System.out.println("You have exceeded the maximum amount of people allowed.");
        }

        int highest = num - 1;
        String available = "";
        String booking = " ";
        int[] RowA = {0, 0, 1, 1, 1, 0, 0, 0, 0, 0};

        for (int i = 0; i < RowA.length; i++) {
            if (RowA[i] == 0) {
                available = available + (i + 1);
            }
            if (available.length() > booking.length()) {
                booking = available;
                System.out.println(booking);
            } else if (RowA[i] == 1) {
                available = "";
            }
        }


        if (num <= booking.length()) {
            char low = booking.charAt(0);
            char high = booking.charAt(highest);
            System.out.println("There are seats from " + low + " - " + high + ".");
        } else {
            System.out.println("The desired seat amount is not available. The maximum amount on Row is " + booking.length());
        }
    }
}
  • 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-18T05:34:26+00:00Added an answer on June 18, 2026 at 5:34 am

    So what you’re doing is a code smell called a Primitive Obsession. You’re using Strings where you should instead be using a more complex data type, such as a collection or array:

    import java.util.*;
    
    public class JavaApplication2 {
    
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter the amount of people in your group, up to 6");
            int num = input.nextInt();
    
            if (num > 6) {
                System.out.println("You have exceeded the maximum amount of people allowed.");
            }
    
            int highest = num - 1;
            ArrayList<Integer> available = new ArrayList<Integer>();
            Integer[] booking = new Integer[0];
            int[] RowA = {0, 0, 1, 1, 1, 0, 0, 0, 0, 0};
    
            for (int i = 0; i < RowA.length; i++) {
                if (RowA[i] == 0) {
                    available.add(i + 1);
                }
                if (available.size() > booking.length) {
                    booking = available.toArray(booking);
                    System.out.println(Arrays.toString(booking));
                } else if (RowA[i] == 1) {
                    available.clear();
                }
            }
    
    
            if (num <= booking.length) {
                int low = booking[0];
                int high = booking[highest];
                System.out.println("There are seats from " + low + " - " + high + ".");
            } else {
                System.out.println("The desired seat amount is not available. The maximum amount on Row is " + booking.length);
            }
        }
    }
    

    Using collections and arrays means that you don’t have to worry about charAt and the number of decimal places because you’re actually manipulating int and Integer types – which will keep track of their decimals on their own.

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

Sidebar

Related Questions

I have written a program that uses qhttp to get a webpage. This works
A program that simply moves array elements. Two variables: userInputVariable and blankSpaceVariable . I
I am writing a program that deals with a 2D array, does calculations based
int main() { int i=3; (++i)++; printf(%d,i); } This programs works with g++ compiler
This is my sample twitter program it works but there are several errors if
I am trying to understand how realloc works. This is my program. It's giving
I have two pointers, each pointing to a different array. One of the pointers
Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
I am trying to write a program for my course that sorts an array
I was wondering why this program actually works in MPI (openMPI 1.5/1.6. ) #include

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.