Skip to content

Commit

Permalink
practice5-ggang9
Browse files Browse the repository at this point in the history
  • Loading branch information
02ggang9 committed Jul 12, 2023
1 parent 1aecc39 commit 970513e
Show file tree
Hide file tree
Showing 28 changed files with 768 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/ArrayPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Practice.ggang9.Chapter3;

public class ArrayPractice {
public static void main(String[] args) {
int[] odds = {1, 3, 5, 7, 9};
String[] weeks = {"월", "화", "수", "목", "금", "토", "일"};

weeks = new String[7];
weeks[0] = "월";
weeks[1] = "화";
weeks[2] = "수";
weeks[3] = "목";
weeks[4] = "금";
weeks[5] = "토";
weeks[6] = "일";

System.out.println(weeks[3]);

}
}
20 changes: 20 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/BooleanPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Practice.ggang9.Chapter3;

public class BooleanPractice {
public static void main(String[] args) {
boolean isSuccess = true;
boolean isTest = false;

int base = 180;
int height = 185;
boolean isTall = height > base;
if (isTall) {
System.out.println("키 큼");
}
}





}
14 changes: 14 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/CharPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Practice.ggang9.Chapter3;

public class CharPractice {
public static void main(String[] args) {
char a1 = 'a'; // 문자로 표현
char a2 = 97; // 아스키코드로 표현
char a3 = '\u0061'; // 유니코드로 표현

System.out.println(a1); // a 출력
System.out.println(a2); // a 출력
System.out.println(a3); // a 출력

}
}
24 changes: 24 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/FinalPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Practice.ggang9.Chapter3;

import java.util.ArrayList;
import java.util.Arrays;

public class FinalPractice {
public static void main(String[] args) {
String num = "123";
int n = Integer.parseInt(num);
System.out.println(n); // 123 출력

String num1 = String.valueOf(n);
String num2 = Integer.toString(n);

final int n1 = 123; // final 로 설정하면 값을 바꿀수 없다.
final ArrayList<String> a = new ArrayList<>(Arrays.asList("a", "b"));





}

}
32 changes: 32 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/ListPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Practice.ggang9.Chapter3;

import java.util.ArrayList;
import java.util.Arrays;

public class ListPractice {
public static void main(String[] args) {
ArrayList pitches = new ArrayList();
pitches.add("138");
pitches.add("129");
pitches.add("142");

pitches.add(0, "133"); // 첫번째 위치에 133 삽입.
pitches.add(1, "133");

System.out.println(pitches.size());
System.out.println(pitches.remove("129"));

ArrayList<String> pitches1 = new ArrayList<>(); // 선호되는 방식
pitches1.add("138");
pitches1.add("129");

String one = pitches1.get(0); // 형 변환이 필요없다.
String two = pitches1.get(1); // 형 변환이 필요없다.

String[] data = {"138", "129", "142"}; // 이미 투구수 데이터 배열이 있다.
ArrayList<String> pitches2 = new ArrayList<>(Arrays.asList(data));
System.out.println(pitches2); // [138, 129, 142] 출력


}
}
22 changes: 22 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/MapPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Practice.ggang9.Chapter3;

import java.util.HashMap;

public class MapPractice {

public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>();
map.put("people", "사람");
map.put("baseball", "야구");

System.out.println(map.get("people")); // "사람" 출력
System.out.println(map.containsKey("people")); // true 출력
System.out.println(map.remove("people")); // "사람" 출력
System.out.println(map.size());
System.out.println(map.keySet()); // [baseball, people] 출력




}
}
28 changes: 28 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/NumberPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Practice.ggang9.Chapter3;

public class NumberPractice {
public static void main(String[] args) {
int age = 10;
long countOfStar = 8764827384923849L;

float pi = 3.14F;
double morePi = 3.14159265358979323846;

int a = 10;
int b = 5;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);

int i = 0;
int j = 10;
i++;
j--;

System.out.println(i); // 1 출력
System.out.println(j); // 9 출력

}

}
29 changes: 29 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/SetPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Practice.ggang9.Chapter3;

import java.util.Arrays;
import java.util.HashSet;

public class SetPractice {
public static void main(String[] args) {

HashSet<String> set = new HashSet<>(Arrays.asList("H", "e", "l", "l", "o"));
System.out.println(set); // [e, H, l, o] 출력

HashSet<Integer> s1 = new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 6));
HashSet<Integer> s2 = new HashSet<>(Arrays.asList(4, 5, 6, 7, 8, 9));

HashSet<Integer> intersection = new HashSet<>(s1); // s1으로 intersection 생성
intersection.retainAll(s2); // 교집합 수행
System.out.println(intersection); // [4, 5, 6] 출력

HashSet<Integer> union = new HashSet<>(s1); // s1으로 union 생성
union.addAll(s2); // 합집합 수행
System.out.println(union); // [1, 2, 3, 4, 5, 6, 7, 8, 9] 출력

HashSet<Integer> substract = new HashSet<>(s1); // s1으로 substract 생성
substract.removeAll(s2); // 차집합 수행
System.out.println(substract); // [1, 2, 3] 출력
}


}
21 changes: 21 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/StringBufferPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Practice.ggang9.Chapter3;

public class StringBufferPractice {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer(); // StringBuffer 객체 sb 생성
sb.append("hello");
sb.append(" ");
sb.append("jump to java");
String result = sb.toString();
System.out.println(result); // "hello jump to java" 출력

StringBuffer sb1 = new StringBuffer();
sb1.append("jump to java");
sb1.insert(0, "hello ");
System.out.println(sb1.toString());



}

}
42 changes: 42 additions & 0 deletions src/main/java/Practice/ggang9/Chapter3/StringPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Practice.ggang9.Chapter3;

public class StringPractice {

public static void main(String[] args) {

// String a = "Happy Java";
String b = "a";
String c = "123";

boolean result = true;
char a = 'A';
int i = 100000;

String a1 = "hello";
String b1 = "java";
String c1 = "hello";
System.out.println(a1.equals(b1)); // false 출력
System.out.println(a1.equals(c1)); // true 출력

String a2 = "hello";
String b2 = new String("hello");
System.out.println(a2.equals(b2)); // true
System.out.println(a2 == b2); // false

String a3 = "Hello Java";
System.out.println(a3.indexOf("Java")); // 6 출력

String a4 = "Hello Java";
System.out.println(a4.charAt(6)); // "J" 출력

String a5 = "Hello Java";
System.out.println(a5.replaceAll("Java", "World")); // Hello World 출력

String a6 = "a:b:c:d";
String[] result1 = a6.split(":"); // result는 {"a", "b", "c", "d"}


}


}
19 changes: 19 additions & 0 deletions src/main/java/Practice/ggang9/Chapter4/ForEachPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Practice.ggang9.Chapter4;

import java.util.ArrayList;
import java.util.Arrays;

public class ForEachPractice {
public static void main(String[] args) {
String[] numbers = {"one", "two", "three"};
for(String number: numbers) {
System.out.println(number);
}


ArrayList<String> numbers2 = new ArrayList<>(Arrays.asList("one", "two", "three"));
for (String number : numbers2) {
System.out.println(number);
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/Practice/ggang9/Chapter4/ForPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Practice.ggang9.Chapter4;

public class ForPractice {
public static void main(String[] args) {
String[] numbers = {"one", "two", "three"};
for(int i=0; i<numbers.length; i++) {
System.out.println(numbers[i]);
}

int[] marks = {90, 25, 67, 45, 80};
for(int i=0; i<marks.length; i++) {
if (marks[i] >= 60) {
System.out.println((i+1)+"번 학생은 합격입니다.");
}else {
System.out.println((i+1)+"번 학생은 불합격입니다.");
}
}

int[] marks1 = {90, 25, 67, 45, 80};
for(int i=0; i<marks1.length; i++) {
if (marks1[i] < 60) {
continue; // 조건문으로 돌아간다.
}
System.out.println((i+1)+"번 학생 축하합니다. 합격입니다.");
}

}
}
62 changes: 62 additions & 0 deletions src/main/java/Practice/ggang9/Chapter4/IfPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package Practice.ggang9.Chapter4;

import java.util.ArrayList;

public class IfPractice {
public static void main(String[] args) {
boolean money = true;
if (money) {
System.out.println("택시를 타고 가라");
}else {
System.out.println("걸어가라");
}

int x = 3;
int y = 2;
System.out.println(x > y);

int money1 = 2000;
if (money1 >= 3000) {
System.out.println("택시를 타고 가라");
}else {
System.out.println("걸어가라");
}

int money2 = 2000;
boolean hasCard = true;

if (money2 >=3000 || hasCard) {
System.out.println("택시를 타고 가라");
} else {
System.out.println("걸어가라");
}

ArrayList<String> pocket = new ArrayList<String>();
pocket.add("paper");
pocket.add("handphone");
pocket.add("money");

if (pocket.contains("money")) {
System.out.println("택시를 타고 가라");
}else {
System.out.println("걸어가라");
}


boolean hasCard2 = true;
ArrayList<String> pocket2 = new ArrayList<String>();
pocket2.add("paper");
pocket2.add("handphone");

if (pocket2.contains("money")) {
System.out.println("택시를 타고 가라");
}else if(hasCard2) {
System.out.println("택시를 타고 가라");
}else {
System.out.println("걸어가라");
}



}
}
Loading

0 comments on commit 970513e

Please sign in to comment.