Can someone tell me what's wrong with my program?

import java.util.Scanner;

public class TotalSales
{
   public void getNumbers()
   {
      Scanner input = new Scanner( System.in );

      double numbers[][] = new double[5][5];
      int count = 0; // number of uniques read
      int x = 0;
      int y = 0;
      int productNum = 1;
      int salesPerson = 1;

      for(int j = 0; 0 < 4; j++)
      {
        for(int i = 0; 0 < 5; i++)
        {

        System.out.printf("Enter the total sales of product %d from salesperson %d", productNum, salesPerson);
        numbers[y][x] = input.nextDouble();

        y++;
        productNum++;
        }// end for

    salesPerson++;
    y = 0;
    x++;

      }// end for 
    }
}

Whenever I try to compile it, it gives me an error message saying "salesPerson++" is an unreachable statement. If I switch "salesPerson++" with "y = 0;" it will say "y = 0;" is an unreachable statement. So we can conclude that is has to do with the first line after the for loop.

I am not sure what is this

for(int j = 0; [B]0 < 4[/B]; j++)
{
for(int i = 0;[B] 0 < 5[/B]; i++)
{
//something
}
//something
}

check out this first and compile again..

Please use code tags people, the code is very ugly without them, and difficult to read. redrocket0274 - what is your program meant to do ? At the moment it doesn't look like its doing much of anything. to use code tags just wrap the code in tags:

code here

without the space between "[CODE and =java".

import java.util.Scanner;

public class TotalSales
{
   public void getNumbers()
   {
      Scanner input = new Scanner( System.in );

      double numbers[][] = new double[5][5];
      int count = 0; // number of uniques read
      int x = 0;
      int y = 0;
      int productNum = 1;
      int salesPerson = 1;

      for(int j = 0; 0 < 4; j++)
      {

      	for(int i = 0; 0 < 5; i++)
      	{
	
		System.out.printf("Enter the total sales of product %d from salesperson %d", productNum, salesPerson);
		numbers[y][x] = input.nextDouble();
	
		y++;
		productNum++;
      	}// end for
		
	salesPerson++;
	y = 0;
	x++;

      }// end for 
    }
}

Even though the program is not completed, I am trying to prompt the user to enter in the total sales of a product (1-5) sold by 4 sales people.

For example, the desired output would be

Enter the total sales for product 1 by sales person 1
Enter the total sales for product 2 by sales person 1
Enter the total sales for product 3 by sales person 1
Enter the total sales for product 4 by sales person 1
Enter the total sales for product 5 by sales person 1

The second for loop will loop back and ask the user for the different product. The first one will ask for the different sales person.

The noparse tag solves the problem of having to do these workarounds by adding a space so it won't parse as Java code.

[noparse]
[noparse]
[code=JAVA]
// code here
[/code]
[/noparse]
[/noparse]

Now if it would only revert back to the old days and stop automatically parsing [noparse][code][/code] as [code=JAVA][/code][/noparse], we'll be in business!

I guess my main question is why will line 29 not compile? It keeps saying it is an unreachable statement. Despite the function of the program, the for loop design is logical so there should be no problem.

I guess my main question is why will line 29 not compile? It keeps saying it is an unreachable statement. Despite the function of the program, the for loop design is logical so there should be no problem.

It IS an unreachable statement. Java doesn't allow unreachable statements. The following condition in red will always be true:

for(int i = 0; 0 < 5; i++)

so your inner for-loop is a black hole. Nothing that goes in will ever come out. Hence line 29 will never be executed under any conditions. Hence it is "unreachable". It would probably compile fine in C++, but Java doesn't allow it. Hence the error.

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.