괴발개발 개발하다
[ Java ] 자바 혼자 연습 본문
package practice_Alone;
import java.util.ArrayList;
import java.util.Scanner;
public class FirstReview {
// public static void printHello() {
// System.out.println("Hello Hello~!!!! 하하하");
public static void main(String[] args) {
//printHello();
// Scanner sc = new Scanner(System.in);
// String name = sc.next();
// int num = sc.nextInt();
// System.out.println(name + "와" + num);
// Student s2 = new Student(29, "홍길동");
// System.out.println("나이는 " + s2.getNum()+ ", 이름은 " + s2.getName());
// s2.setNum(30);
// s2.setName("룰루");
// System.out.println("내년에는 나이가 " + s2.getNum() + "이고, 이름은 " + s2.getName());
Student[] es =new Student [3];
Student s1 = new Student(1, "홍길동");
Elementary s2 = new Elementary(2, "임꺽정");
Middle s3 = new Middle(3, "김원봉");
es[0] = s1;
//es[0] = new Student(2, "최최최");
es[1] = s2;
es[2] = s3;
System.out.println(es[1].getName());
System.out.println(es[2].getNum());
es[1].getupEarly();
es[2].getupEarly();
//for문
for(int i = 0; i<es.length; i++) {
es[i].study();
}
s1.setScore(100);
s2.setScore(70);
s3.setScore(90);
System.out.println(s1.getName() + "의 점수는 " + s1.getScore() + "점");
for(int i = 0; i<es.length; i++) {
System.out.println(es[i].getName() + "의 점수는 " + es[i].getScore() + "점");
}
///////////////////////////////////////////////////////////////////
FirstReview fr = new FirstReview();
ClassA c = new ClassA();
ClassA ca = new ClassA("박태환");
ca.dec = 70;
ca.setStr("연습연습연습");
System.out.println(ca.dec);
System.out.println(ca.getStr());
//////////////////////////////////////////////////////////////////
//배열 연습
Student[] sArray = new Student[3];
sArray[0] = new Student(1, "랄랄");
sArray[1] = new Student(2, "꾸꾸");
sArray[2] = new Student(3, "빠빠");
sArray[0].setNum(11);
sArray[1].setNum(22);
sArray[2].setNum(33);
for(int i = 0; i<sArray.length; i++) {
System.out.println(sArray[i].getNum() + "이랑 " + sArray[i].getName());
}
//향상된 for문
for(Student s : sArray) {
System.out.println(s.getNum());
}
///////////////////////////////////////////////////////////////
//ArrayList
ArrayList<Student> sList = new ArrayList<Student>();
Student stu = new Student(1, "ch");
sList.add(stu);
sList.add(new Student(2, "갱갱"));
sList.add(new Student(3, "뿡"));
sList.get(0).setNum(50);
sList.get(1).setName("미스터");
sList.get(2).setNum(58);
for(int i = 0; i<sList.size(); i++) {
System.out.println(sList.get(i).getNum() + " " + sList.get(i).getName());
}
for(Student s : sList) {
System.out.println(s.getNum() + " " + s.getName());
}
}//main
}
'자바' 카테고리의 다른 글
[ Java ] 자바 Arrays로 배열 다루기(toString(), equals(), copyOf(), sort()) (0) | 2022.07.05 |
---|---|
[ Java ] 자바 2차원 배열 예제 (0) | 2022.07.05 |
[ Java ] 자바 배열의 활용(총합/평균, 최대값/최소값) (0) | 2022.07.04 |
[Java] 자바 배열 값 출력 (0) | 2022.07.04 |
[JAVA] 자바 환경변수 설정 이유 & 설정 방법 (0) | 2022.06.07 |