# How to find where the biggest number is in an array

• May 1st, 2013, 10:09 PM
Jazz26
How to find where the biggest number is in an array
Hi i've been trying to figure out where to find the biggest number in an array. I know how to find the biggest number but i need to find out where the biggest number is, like which row or whatever it's in.

Code :

```import java.util.Scanner; public class array {   public static void main (String args[]) {   Scanner keyboard = new Scanner(System.in);   int r[] = new int[50]; int n=0; int x, bigSoFar;   System.out.print("Enter list: "); x = keyboard.nextInt();   while( x!= -999); { r[n] = x; n++; x = keyboard.nextInt(); }   for(int k = 0; k < n; k++) if(r[k]> bigSoFar) {   bigSoFar = r[k]; }   System.out.println(r[k]);   } }```

Although first i'm having trouble trying to get my first code to work, i keep getting this error
array.java:34: error: cannot find symbol
System.out.println(r[k]);
^
symbol: variable k
location: class array
1 error
• May 1st, 2013, 10:14 PM
jps
Re: How to find where the biggest number is in an array
Check the { }
It seems the compiler believes k is not defined within scope every time it is being used.
Look at line 34's use of k
• May 1st, 2013, 10:31 PM
Jazz26
Re: How to find where the biggest number is in an array
k is defined as k=0 inside the parenthesis and as for the braces, where else could i place them?
• May 1st, 2013, 10:44 PM
jps
Re: How to find where the biggest number is in an array
Check the positioning of the { } again. For some reason the scope of the for loop does not include k on line 34.
Code java:

```class ForDemo { public static void main(String[] args){ for(int i=1; i<11; i++){ System.out.println("Count is: " + i); } for(int i=1; i<11; i++) System.out.println("Count is: " + i); System.out.println("I am outside the loop); } }```
If the for loop is not followed by a curly brace, but instead followed by a statement ending with a semicolon, the scope of the for loop terminates at the semicolon. Demonstrated by the class above, a modified version from the java for loop tutorial
• May 1st, 2013, 11:12 PM
Jazz26
Re: How to find where the biggest number is in an array
ok I fixed it and I was able to compile it but now whenever i try to put a list in in the command prompt it will just sit there and not do anything, just freeze and think. I can't figure it out
• May 1st, 2013, 11:32 PM
Junky
Re: How to find where the biggest number is in an array
Post updated code.
• May 1st, 2013, 11:46 PM
Jazz26
Re: How to find where the biggest number is in an array
Code :

```import java.util.Scanner;   public class array {   public static void main (String args[]) {   Scanner keyboard = new Scanner(System.in);   int r[] = new int[50]; int n=0; int x, bigSoFar=0;   System.out.print("Enter list: "); x = keyboard.nextInt();   while( x!= -999); {   r[n] = x; n++; x = keyboard.nextInt();   }   for(int k = 0; k < n; k++){ if(r[k] > bigSoFar) {   bigSoFar = r[k]; }   System.out.println(r[k]); }   }     }```
• May 2nd, 2013, 06:07 AM
Norm
Re: How to find where the biggest number is in an array
Quote:

it will just sit there and not do anything, just freeze and think.
Is it waiting for the user to enter more data? What happens when more data is typed in?
What does it do if -999 is entered?

Add some calls to the println statement to print out messages as the code executes to show you where it is executing.