int plus(int a, int b){
return a+b;
}
int result = plus(100, 200);
//가변 파라미터를 이용하는 경우
void hello(String ...names){
for(int i=0;i<names.length;i++){
System.out.printf(names[i]);
}
}
public static void main(String[] args){
// 배열을 만들어서 전달 가능
String[] arr = {"김구", "안중근", ..., "유관순"};
hello(arr);
// 바로 전달도 가능
hello("김구", "안중근", ..., "유관순");
}
//일반 배열 파라미터를 이용하는 경우
void hello(String[] names){
for(int i=0;i<names.length;i++){
System.out.printf(names[i]);
}
}
public static void main(String[] args){
// 배열을 만들어서 전달 가능
String[] arr = {"김구", "안중근", ..., "유관순"};
hello(arr);
// 바로 전달 불가능
hello("김구", "안중근", ..., "유관순");
}
for(String value:arr){
System.out.println(value);
}
static class MyObject{
int a;
int b;
}
static void swap(MyObject ref){
int temp=ref.a;
ref.a = ref.b;
ref.b = temp;
}
public static void main(String[] args){
MyObject ref = new MyObject();
ref.a = 100;
ref.b = 200;
swap(ref);
}
static class MyObject{
int a;
int b;
}
static MyObject swap(int a, int b){
MyObject ref = new MyObject();
ref.a = b;
ref.b = a;
return ref;
}
public static void main(String[] args){
int a = 100;
int b = 200;
MyObject ref = swap(a, b);
print(ref.a, ref.b);
}
$ java 클래스명 값1 값2 값3
$ java Exam 0520 aaa bbb ccc
-> main(String[] args){-}에서 String args에 aaa, bbb, ccc가 new String("aaa", "bbb", "ccc")로 들어가게 된다.
$java -cp ./bin/main/
-D이름=값 -D이름=값 -D이름=값
com.eomcs.basic.ex07.Exam0610
$System.getProperty("이름");
// 원래 코드
static void edit(int editIdx) {
Board board = boards[editIdx];
String title= Prompt.inputString("제목? " + "("+board.title+")");
String content= Prompt.inputString("내용? "+ "("+board.content+")");
String writer = Prompt.inputString("작성자? "+ "("+board.writer+")");
String password = Prompt.inputString("암호? "+ "("+board.password+")");
if(isEdit()) {
board.title =title;
board.content =content;
board.writer=writer;
board.password = password;
System.out.println("성공적으로 변경되었습니다!");
}else {
System.out.println("변경을 취소하였습니다.");
return;
}
}
// 수정된 코드
static void edit(int editIdx) {
Board board = boards[editIdx];
String title= Prompt.inputString("제목? " + "("+board.title+")");
String content= Prompt.inputString("내용? "+ "("+board.content+")");
String writer = Prompt.inputString("작성자? "+ "("+board.writer+")");
String password = Prompt.inputString("암호? "+ "("+board.password+")");
if(isEdit()) {
board = makeBoard(title, content, writer, password);
System.out.println("성공적으로 변경되었습니다!");
}else {
System.out.println("변경을 취소하였습니다.");
return;
}
}
static Board makeBoard(String title, String content, String writer, String pwd) {
Board board = new Board();
board.title =title;
board.content =content;
board.writer=writer;
board.password = pwd;
return board;
}
-> 지금보니까 파라미터로 board를 넘겨줬어야 했는데 어떻게 작동한거지,,?