I'm a first year programmer.
I've been trying to search an array which has stored four variables, with an input.
All of the examples I've found make use of int, and searches for a number within a list.
My program must search for a combination of letters and numbers. (Ex. COP 2800)
import java.util.Scanner;
public class courseInfo {
public static int courseInfo(int[] list, int key) {
Scanner input = new Scanner(System.in);
// Input course name
System.out.print("Enter course name: (Ex. COP 2800) ");
double courseInput = input.nextDouble();
for (int i = 0; i < list.length; i++) {
if (key == list[i])
return i;
}
return -1;
}
public static void main(String[] args) {
int[] list = {COP 2800, PSY 1012, EVR 2001, COP 1000};
System.out.println(linearSearch(list, courseInput));
}
}
Please use layman's terms, I've only been in this class for three weeks.
If I remove COP, PSY, EVR, and COP from line 21, I return a different error;
courseInfo.java:22: error: cannot find symbol
System.out.println(linearSearch(list, courseInput));
^
symbol: variable courseInput
location: class courseInfo
1 error