in Attached Files there is Question i do not understand the last step

how to coount it ?

package javaapplication178;
public class JavaApplication178 {
    public static void main(String[] args) {
       int x[][]={{14,7,5,0},
           {9,20,25,12},
           {25,25,40,30}}; 
       
      for(int i=0;i<x.length;i++) 
      { 
          
          for(int y=0;y<x[i].length;y++) 
          { 
              System.out.print(x[i][y] + " "); 
              
          } 
          System.out.println("  ");
      }
     
     
      PrintStock(  x);
      System.out.println("  ");
    }
    public static void PrintStock( int x[][]){
        int count=1;
         for(int i=0;i<x.length;i++) 
      { 
          
          for(int y=0;y<x[i].length;y++) 
          { 
            if(x[i][y]<10){
            count++;
                 System.out.print(count++ + " "); 
            }
            
             
          } 
         
      } 
    }
}

Recommended Answers

All 10 Replies

I'm not going to go through an attachment, is i that much trouble to copy paste your assignment in this thread along with your code?

A company owns four stores, each of which can store four particular items. The current item stock in these stores is:
ITEMS
1 2 3 4
STORE#1 14 7 5 0
STORE#2 9 20 25 12
STORE#3 25 25 40 30

Write a program which will read the stock data in a two-dimensional INTEGER array STOCK it then determines for each store the number of items with stock below ten. You should have a method PrintStock(), this method will read STOCK and display it on the console.

Your output should be in the form:

STORE#1 14 7 5 0
STORE#2 9 20 25 12
STORE#3 25 25 40 30

NUMBER OF ITEMS WITH STOCK BELOW 10:

STORE# NUMBER OF ITEMS
1 3
2 1
3 0

well, first of all:
in printStock, your count has to be set to 0 to get the right results
and it has to be reset to 0 for each store, so within the for-loop.

next, you're not supposed to have a print inside your inner-for loop.
put your System.out.println(String.valueOf(count));
right behind your inner for-loop

What does your code currently print out and what more does it need?
Can you paste here the program's current output?

he's not resetting his count and he's printing each time he adds a number to it, instead of just the total :)

package javaapplication178;
public class JavaApplication178 {
    public static void main(String[] args) {
       int x[][]={{14,7,5,0},
           {9,20,25,12},
           {25,25,40,30}}; 
       
      for(int i=0;i<x.length;i++) 
      { 
          
          for(int y=0;y<x[i].length;y++) 
          { 
              System.out.print(x[i][y] + " "); 
              
          } 
          System.out.println("  ");
      }
     
     
      PrintStock(  x);
      System.out.println("  ");
    }
    public static void PrintStock( int x[][]){
        int count=0;
         for(int i=0;i<x.length;i++) 
      { 
          
          for(int y=0;y<x[i].length;y++) 
          { 
            if(x[i][y]<10){
            count++;
                 System.out.println(String.valueOf(count)); 
            }
            
             
          } 
         
      } 
    }
}

the output

14 7 5 0   
9 20 25 12   
25 25 40 30   
1
2
3
4

You have left off the String text that identifies each line. For example the text in red:
STORE#1 14 7 5 0

What labels should be on lines 4-7 in what you show for the print out?
Your sample printout shows that there are header lines like this:
STORE# NUMBER OF ITEMS

Where are they?

as I said: you need to reset the value of count each time your outer for loop runs, and you have to put your println of your count variable in your outer for loop, after the running of your inner for-loop.

as I said: you need to reset the value of count each time your outer for loop runs, and you have to put your println of your count variable in your outer for loop, after the running of your inner for-loop.

i do not understan this step

what's there to understand? it's copy pasting two lines to other locations in the same method.

do you know which lines I'm referring to, and if so, do you know what the inner and outer for loop are?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.