import java.util.*;
class Phone {
private String name;
private String tel;
public Phone(String name, String tel) {
this.name = name;
this.tel = tel;
}
public String getName() {
return name;
}
public String getTel() {
return tel;
}
}
class Main {
Phone[] arr;
public void run()
{
Scanner sc = new Scanner(System.in);
int k;
String name1;
System.out.print("인원수 >> ");
k=sc.nextInt();
arr=new Phone[100];
for(int i=0;i<k;i++)
{
System.out.print("이름과 전화번호(이름과 번호는 빈 칸 없이 입력) >> ");
String name=sc.next();
String tel=sc.next();
arr[i]=new Phone(name,tel);
}
System.out.println("저장되었습니다...");
while(true)
{
System.out.print("검색할 이름 >> ");
name1=sc.next();
if(name1.equals("그만")) break;
boolean flag=false;
for(int i=0;i<k;i++) {
if(name1.equals(arr[i].getName())) {
System.out.println(name1+"의 번호는 "+arr[i].getTel()+" 입니다.");
flag=true;
break;
}
}
if(flag==false) System.out.println("\n"+name1+" 이 없습니다.");
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
static 같은 클래스로 만들어진 객체들이 공유하는 공간
import java.util.*;
class Phone {
static int num=0;
private String name;
private String tel;
public Phone(String name, String tel) {
this.name = name;
this.tel = tel;
}
public static void upNum() {
num++;
//tel="hi"; static 메소드에서 non-static 필드를 접근 할 수 없다!!
}
public String getName() {
return name;
}
public String getTel() {
return tel;
}
}
class Calculator{
static int add(int a, int b) {
return a+b;
}
}
class Main{
public static void main(String[] args) {
System.out.println(Calculater.add(5, 8));
Phone p = new Phone("aaa", "111");
Phone s = new Phone("bbb", "222");
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
p.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
s.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
Phone.upNum();
System.out.println(p.num + " "+ s.num+ " "+Phone.num);
}
}
*/
class ArrayUtil{
public static int [] concat(int[] a,int[] b) {
int[] c = new int[a.length+b.length];
for(int i=0;i<a.length;i++)
{
c[i]=a[i];
}
for(int i=0;i<b.length;i++)
{
c[i+a.length]=b[i];
}
return c;
}
public static void print(int[] a) { for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); }
}
class Main{
public static void main(String[] args) {
int [] array1= {1,5,7,9};
int [] array2= {3,6,-1,100,77};
int [] array3 =ArrayUtil.concat(array1,array2);
ArrayUtil.print(array3);
}
}



