본문 바로가기

java45

0922_배열 public class ArrayTest { //0922:array public static void main(String[] args) { //배열 : 동일한 타입의 변수를 여러개 정의 하는 것 /*int[] arr; //배열의 선언 arr = new int[5]; //배열의 생성. 5개를 담을 거라는 뜻 arr[0] = 10; //인덱스를 활용한 값 할당 arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50; System.out.println(arr[0]); System.out.println(arr[1]); System.out.println(arr[2]); System.out.println(arr[3]); System.out.println(arr[4]); */ /.. 2022. 9. 22.
0922_반복문의 제어 //반복문의 제어 : continue -----------------------------------------0922 //for(int i=1;i 1+2+3+4+5 -> 15 //몇번 반복해야할지 모르니까 while문 추천 //Scanner sc = new Scanner(System.in); //int num = sc.nextInt(); //int sum = 0; // //while(num > 0) { //sum += num % 10; //num = num / 10; //} //System.out.println(sum); //%, /를 반복 //12345 % 10 => 5 //12345/ 10 => 1234 //1234%10 -> 4 //1234%10 -> 123 //num>0 될때까지 //앞부터 추출.. 2022. 9. 22.
0921_반복문 public class LoopTest { // 0921 반복문 public static void main(String[] args) { // 반복문 : 실행문을 여러번 동작하게 한다. // for, while, do-while(보통 잘 안씀) //for(초기문; 조건식; 증감식) { //실행문 //} //for(int i=0; i 2022. 9. 22.
0921_조건문 import java.util.Scanner; public class IfTest { // 0921 조건문 public static void main(String[] args) { // 조건문 : 실행 문장을 선택적으로 실행 // if, switch ~ case //if(조건식(true or false) { //조건식은 논리값으로true or false //실행문 //int age = 15; //if(age >= 20) { // true //System.out.println("성인입니다."); //}else { //System.out.println("미성년 입니다."); //} // // //int num = 10; //if(num % 2 == 1) { //System.out.println("홀수"); .. 2022. 9. 22.
0920_Scanner import java.util.Scanner; public class ScannerEx { // 0920 public static void main(String[] args) { //System.out.println("이름, 도시, 나이, 체중, 독신 여부를 빈칸으로 분리하여 입력하세요"); //Scanner sc = new Scanner(System.in); //String name = sc.next(); //System.out.println("이름은 "+name+","); // //String city = sc.next(); //System.out.println("도시는 "+city+","); // //int age = sc.nextInt(); //System.out.println("나이는 "+age.. 2022. 9. 20.
0920_연산자 public class Oper { // 0920 public static void main(String[] args) { //int x = 5; //int y = 2; //System.out.println(x / y); //System.out.println(x % y); //final double PI = 3.14; //System.out.println(PI); //double PI = 2.14; 상수는 변경할 수 없음 //형변환(자료형 or 데이터 타입) //int -> double //boolean 은 제외 //--> 자동형변환 //byte (1 byte)< short(2byte) < int(4byte)값의기준 < long 8 < float 4 (값을 표현할 수 있는 범위가 더 커서(실수까지가능)l.. 2022. 9. 20.