본문 바로가기

분류 전체보기

(82)
(번외) do while 연습 (feat. 증감연산자) do while에서 헷갈렸던 이유는 증감연산자 (전위, 후위 연산) 덕분이다. count ++ 후위연산현재 실행중인 문장에서는 기존값이 그대로 사용됨, 그 다음 실행된 문장부터 증가된 값이 반영++ count전위연산먼저 1 증가 -> 바로 증가된 값 사용 이게 하나의 개념으로서는 이해되지만, 이걸 문장에 넣어놓고 갖고놀 수 있는 정도로는 편해지지 않았다. 그리고 일단, 후위연산을 가지고 연습하되, 후위연산이 어디에 배치되느냐에 따라서도 결과값이 달라질 수 있음을 do while 연습을 통해 확인해보겠따. public class practice_01 { public static void main(String[] args) { int count = 0 ; do { Syst..
25. (Loops and Conditions) Do While Loop Do-While Loop: always excutes at least once even if the condition is false 컨디션이 거짓이라도 최소한 한번은 실행된다. public class App { public static void main(String[] args) { boolean loopCondition = false; do { System.out.println("안녕하시렵니까? "); } while (loopCondition); }} loopCondition이 거짓인 상황에서 실행하면 출력은 단 한번만 한다. 하지만 조건을 참으로 둔다면... public class App { public static void main(String[] args) { boolean loo..
24. (Loops and Conditions) Checking Passwords (실패코드 포함) password는 우리가 평소에도 많이 접하기 때문에 이해하기 쉬운 개념이다. 매우 적절하게 final을 배웠고, password는 값이 정해져있기 때문에 final을 쓰는것과, 변수를 대문자로 쓰는것 등등. 배운것이 바로 나오는 시간이었따. package application;import java.util.Scanner;public class App { public static void main(String[] args) { final String USER_PASSWORD = "hello"; System.out.println("Enter password > "); Scanner scanner = new Scanner(System.in); String password = scanner.nextL..
02. Emo 창 만들기 (Swing) 1. 창 만들기package EmoPro;import javax.swing.JFrame;public class App { public static void main(String[] args) { JFrame frame = new JFrame("My first Swing window"); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }} 2. 창에 번호붙이기 package EmoPro;import java.awt.Dimension;import java.awt.FlowLayout;import javax.swing.JButton;import ..
01. EmoPro 개요 자바로 프로그램 만들기. 챗지피티가 있으면 못만들게 없다. ! EmoPro: 달력같은걸 ui로 띄워놓고, 그날그날 내 기분을 색깔? 이나 도형으로 표시하면서 내 기분을 한눈에 모니터링 할 수 있는 프로그램달력 UI 만들기 (날짜별로 버튼이나 셀 만들기) 날짜 클릭하면 내 기분 선택할 수 있게 (색깔이나 도형 선택) 선택한 기분을 날짜 셀에 표시하기 프로그램을 다시 실행해도 저장된 데이터 불러오기 (파일 저장)Swing으로 간단한 윈도우 띄우고, 그 안에 날짜 버튼 몇 개만 만들어 보는 거부터 시작 swing은 뭐야? 앱으로 만들 필요 --> 없음 웹으로 띄울 필요 --> 없음 그냥 로컬에서 돌아가는 약간 메모장 앱 정도로 봐도 좋음. 기능 복잡? --> 없음, 그냥 달력에 표시하는거임. (다만, 어떤 ..
23. (Loops and Conditions) Break Break: 괄호 안에서 계속 반복적으로 진행되는 작업(반복문 혹은 switch)들을 멈추고, 범위 밖의 프로그램을 가동시킨다. public class App { public static void main(String[] args) { int count = 0; while (true) { System.out.println("안녕! " + count); if (count == 3) { break; } System.out.println("잘 지내셨냐능? " + count); count++; } System.out.println("프로그램을 종료합니다."); }} while(true)는 무한반복의 의미이지만 , 그 아래에서 따라나온 if문에서 count가 3번째 될 때 bre..
22. (Loops and Conditions) The Final Keyword The Final Keyword: final 이라는 키워드를 붙여두면, 그 이후에 변수값이 바뀔 수 없다. (변수가 확정된다는 의미 같다. ) 값이 변경되면 안되는 경우 사용한다고. 예를 들어public class App { public static void main(String[] args) { int value = 9; System.out.println(value); value = 11; System.out.println(value); }} value 변수 값이 2번 지정되었는데, 처음에는 9, 두번째는 11이다. 실행하면 아래와 같이 두 값 모두 출력된다. 만약 처음 value 변수 값을 지정할 때 final 키워드를 넣는다면? 차후에 나오는 value값을 지정할 수 없다. int ..
21. (Loops and Conditions) The String Equals Method String Equals Method문자열을 비교할 때에는 equals equals == 대신 실제 equals 메서드를 사용해야된다.(리터럴 일 경우) == 가 문제 없는 결과를 출력할 수도 있지만, 사실 문자열을 비교할 때 사용하는 적절한 메서드는 equals 임. public class APp { public static void main(String[] args) { String text1 = "orange"; String text2 = "apple"; String text3 = "apple"; System.out.println(text1 == text2); System.out.println(text2 == text3); //아래 코드와 기능이 똑같다? System...
20. (Loops and Conditions) Switch Fallthrough Switch Fallthroughbreak; it breaks out of the switch statement at that point. when we don't have break statement in a switch, when we just start somehwere and then do all the options afterwards. we say we're falling through to the other case statement and this is sometimes useful so it's perfectly valid to have a switch statement with no breaks in it or only with breaks in certain places. ..
19. (Loops and Conditions) Switch Switch : 정확한 정의는 모르겠다. 다만 if, else if, else 등과 비교했을때 훨씬 더 간소하게 사용되니 if / else 의 replacement라는 의미로 switch를 쓴게 아닐까 지금 추측 중 챗지피티에 따르면 switch가 if/ if else에 비해 더욱 간소하고, 유지보수도 훨씬 더 수월함. 다만 간소한 업무에 특화되어있고, 정교성(복잡한 조건, 넓은 범위 커버해야 할 경우) 을 요한다면 if / if else 사용하는것이 바람직하다. 맨 처음에 배울때 if 문을 보여주다가 다시 돌아와서 switch를 작성했다. public class App { public static void main(String[] args) { int option = 8; switch (opt..