I have to create a method to find the biggest number via an array.
I have tried this:
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner enter = new Scanner (System.in);
int[] tab = {10,4,23,45,28,34,89,9,16,55};
int choice = 0;
do{
System.out.println("*********Menu*********");
System.out.println("1) - The biggest number : ");
System.out.println("9) - Exit :");
System.out.print("Enter your choice please : ");
choice = enter.nextInt();
switch(choice){
case 1:
System.out.println("Option 1 :");
biggest_number(big);
break;
}
} while(choice != 9);
}
public static int biggest_number(int big){
for(int i=0;i<tab.length;i++){
if(tab[i] > big){
big = tab[i];
}
}
return big;
System.out.print("The biggest number is => " + big);
}
}
I have several error messages:
Main.java:23: error: cannot find symbol
biggest_number(big);
^
symbol: variable big
location: class Main
Main.java:34: error: cannot find symbol
for(int i=0;i<tab.length;i++){
^
symbol: variable tab
location: class Main
Main.java:35: error: cannot find symbol
if(tab[i] > big){
^
symbol: variable tab
location: class Main
Main.java:36: error: cannot find symbol
big = tab[i];
^
I don't understand my errors? I have declared a parameter which is called big
.
Is it return
is correct also according you?
For information: I am obliged to use a method for my learning in Java.