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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:27:23+00:00 2026-06-15T18:27:23+00:00

I’m working on a school assignment and I’m having an issue with a 2d

  • 0

I’m working on a school assignment and I’m having an issue with a 2d array. Basically my program takes an integer from the the user and determines if one of the array values is lower than that integer. I have a while and for loop set up to do the trick, but I can’t seem to get my loop to use the last row of data. I’ve tried mixing things around for a couple of hours now.

I’m sure I’m derping really badly on whatever I’m missing, but I could use a hand now.
Here is the relevant data for my code

    //array of store inventory
    int invArray[][] = {{102, 54, 20, 78}, 
                        {45, 25, 35, 75},
                        {12, 35, 45, 65},
                        {54, 25, 34, 45},
                        {15, 35, 50, 25}};
    int menuChoice = 0;                     //allows user to select a menu option
    int storeNum=0;                         //store number
    String itemName="null";                 //name for an item
    int itemAmount=0;                       //items below this amount are pulled up in choice 4
    int arrayRow=0;                         //row value for invArray based on itemName
    int arrayCol=0;                         //column value for invArray based on storeNum


       //menu 4
        if (menuChoice == 4){
            System.out.print("Find all items below the number: ");

            //catches mistakes
            try{
            itemAmount = input.nextInt();
            }
            catch(Exception e){
                System.out.print("Invalid value entered. Try again: ");
                itemAmount = input.nextInt();
            }
            System.out.println("Items below "+itemAmount+": ");

            //loop that checks item values at all stores
            arrayRow=0; 
            arrayCol=0;                         //counters for loop
            while (arrayCol < invArray[arrayRow].length){

                for (arrayRow = 0; arrayRow < invArray[arrayCol].length; arrayRow++){


                    if (invArray[arrayRow][arrayCol] < itemAmount){


                        if (arrayRow == 0)
                            itemName = "Tennis Shoes";
                        if (arrayRow == 1)
                            itemName = "Sweaters";
                        if (arrayRow == 2)
                            itemName = "Jeans";
                        if (arrayRow == 3)
                            itemName = "Shorts";
                        if (arrayRow == 4)
                            itemName = "Jackets";


                        //outputs stores with values lower than the one given
                        System.out.println("Store 10"+(arrayCol+1)+" "+itemName+": "
                        +invArray[arrayRow][arrayCol]);

                        for (int i = 0;invArray[4][i] < invArray[arrayRow].length; i++)
                            System.out.println("Store 10"+(i+1)+" "+" jackets : "+invArray[i][4]);
                    }


            }       
                arrayCol++;
                System.out.println();
        }//end item check loop
    }
  • 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-15T18:27:24+00:00Added an answer on June 15, 2026 at 6:27 pm

    You have wrong second loop. It should be

    for (arrayRow = 0; arrayRow < invArray.length; arrayRow++){
    

    since arrayRow is the first index. In you code you get 4 instead of 5 which causes an error.

    Also you would better use for for both loops.

    And also you should better have column loop inside row loop, since former is dependent, or you should exchange indices;

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.