Java:
import java.util.Scanner;
import java.io.*;
public class GB_Project3 {
File english = new File("english.txt");
File panjabi = new File("panjabi.txt");
Scanner readEnglish = new Scanner(english);
Scanner readPanjabi = new Scanner(panjabi);
Scanner input = new Scanner(System.in);
int count = 0;
int line = 0;
String translate = "";
System.out.println("Enter an english word: ");
String userInput = input.nextLine();
while (readEnglish.hasNextLine()) {
String englishInfo = readEnglish.nextLine();
if (englishInfo.equals(userInput)) {
line = count;
}
count++;
}
if (line == 0) {
System.out.println("This word does not exist in our dictionary!");
} else {
for (int i = 0; i < line; i++) {
translate = readPanjabi.nextLine();
}
System.out.println(translate);
}
}
}
The point of this code is to see if a user's input matches a text file, and then translate it to panjabi. It will do this fine for every single word EXCEPT the first line, "my". I have tried debugging this for hours and have no idea what to do. I am still a beginner and have tried searching for answers but have not found anything and have resorted to posting on a forum.