-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNames.java
More file actions
57 lines (46 loc) · 1.46 KB
/
Copy pathNames.java
File metadata and controls
57 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package intro;
import java.util.Scanner;
import java.io.FileReader;
import java.io.BufferedReader;
public class Names {
public static void main(String[] args) throws Exception
{
FileReader myFile = new FileReader("names.txt");
BufferedReader myReader = new BufferedReader(myFile);
int i = -1;
String inputName, firstName = myReader.readLine(); //get first line of text from file
boolean isCommon = true;
String [] nameBank = new String [100];
while(firstName != null)
{
i++;
nameBank[i] = firstName;
firstName = myReader.readLine(); //get next name, returns null if end of file
}
myReader.close();
myFile.close();
Scanner takeUserInput = new Scanner(System.in);
System.out.println("Enter a name to see if it is common or not (case does not matter): ");
inputName = takeUserInput.next();
for (int j = 0; j < nameBank.length; j++)
{
if (inputName.equals(nameBank[j]))
{
isCommon = true;
}
else
{
isCommon = false;
}
}
takeUserInput.close();
if (isCommon)
{
System.out.println("Yes that is a common name");
}
else
{
System.out.println("No, that is not a common name");
}
}
}