-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaRenB.java
52 lines (43 loc) · 1.53 KB
/
JavaRenB.java
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
import java.io.*;
class JavaRenB {
//class Array1
public static void main(String[] args) throws IOException {
BufferedReader bin = new BufferedReader ( new InputStreamReader(System.in) );
//=== Variable declaration ===
String names[] = {"Kudoh", "Satoh", "Katoh", "Saitoh", "Sudoh"}; //氏名群
String adrss[] = {"Aichi", "Kyoto", "Chiba", "Miyagi", "Tokyo"}; //住所群
String nm;
int ad_array[] = new int[names.length],for_i;
Address address = new Address(names,adrss,ad_array) ;
//=== main ===
println("> 前方一致で検索を行います。");
print("> 検索氏名を入力してください : ");
ad_array = address.match(bin.readLine());
for (for_i = 0; for_i < names.length; for_i++) {
if (ad_array[for_i] >= 0) {
println(names[for_i] +" : "+ adrss[for_i] );
}
}
}
public static void print(String hoge){
System.out.print(hoge);
}
public static void println(String hoge){
System.out.println(hoge);
}
}
class Address {
String names[],addresis[];
int i,match_i,add_array[];
public Address (String names_input[],String addresis_input[],int ad_array[]) {
names = names_input ;
addresis = addresis_input;
}
public int[] match (String nm) {
add_array = new int[names.length];
for (i = 0; i < names.length; i++){
add_array[i] = names[i].indexOf(nm);
}
return add_array;
}
}