Hello guys, i'm having trouble with creating a sequential search algorithm for a two dimensional int array. not sure exactly how to go about augmenting the while loop so it works , the example i'm using does it exactly how i wrote it out, as you can see my compiler is complaining about the incompatibility with the way its written out!
import java.util.*;
import javax.swing.*;
public class pencilneck
{
public static void main(String []alex)
{
int ROWS = 6;
int COLS = 3;
int[][] chargeAcc = new int[ROWS][COLS];
Scanner keyboard = new Scanner(System.in);
for(int row = 0; row < ROWS; row++)
{
for(int col = 0; col < COLS; col++)
{
System.out.print("Enter Account");
chargeAcc[row][col] = keyboard.nextInt();
}
}
System.out.print("Enter an account to be Charged");
int input = keyboard.nextInt();
int results = SequentialSearch(chargeAcc,input);
if(results ==-1)
{
System.out.println("that is an invalid #");
}
else
{
System.out.println("the # is valid");
}
}
public static int SequentialSearch(int[][] array, int value)
{
int index1 = 0;
int element = -1;
boolean found = false;
while(!found && index1 == value)
{
if(array[index] == value)
{
found = true;
element = index;
}
index++;
}
return element;
}
}