java (22) 썸네일형 리스트형 java 조건문 switch 예제 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("숫자입력 >> "); int sNum = sc.nextInt(); switch(sNum) { case 0: System.out.println("0을 입력했습니다."); break; case 1: System.out.println("1을 입력했습니다."); break; case 2: System.out.println("2을 입력했습니다."); break; case 3: System.out.println("3을 입력했습니다."); break; defau.. java 조건문 if 예제 import java.util.Scanner; public class Main { public static void main(String[] args) { boolean condition = true; if(condition) { System.out.print("조건 만족 : "); System.out.println("condition = "+ condition); }else { System.out.print("조건 불만족 : "); System.out.println("condition = "+ condition); } int num1 = 5, num2 = 5; if(num1 > num2) { System.out.print("조건 만족 : "); System.out.println("num1이 num.. java 입력 scanner 예제 import java.util.Scanner; public class ex01_Scanner { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.print("이름 입력 >> "); String name = sc.next(); System.out.print("나이 입력 >> "); int age = sc.nextInt(); sc.nextLine().trim(); // trim()앞뒤 공백을 제거한다. System.out.print("주소 입력 >> "); String address = sc.nextLine(); System.out.. java 문자 예제 public class Main { public static void main(String[] args) { // 문자형 변수타입 char(2byte) //문자형 변수에 값을 할당할 경우 ""가 아닌 ''를 사용해야 한다. char ch1 = 'a'; System.out.println(ch1); System.out.println((int)ch1); int num1 = 97; System.out.println((char)num1); String str1 = "자바공부는 "; String str2 = "재미있어요."; String result; result = str1+str2; System.out.println(result); System.out.println(str1 + "많이 " + str2); .. java 데이터 타입 예제 public class Main { public static void main(String[] args) { //정수형 데이터 타입 //(1) byte // 1byte = 8bit // 1byte = -2^7 ~ (2^7-1) // -128 ~ 127 byte bNum = 123; //(2) short // 2byte = 16bit // 2byte = -2^15 ~ (2^15-1) // -32,768 ~ 32,767 short sNum1 = 123; //(3) int // 4byte = 32bit // 4byte = -2^31 ~ (2^31-1) // –2,147,483,648 ~ 2,147,483,647 int iNum1 = 123; //(4) long // 8byte = 64bit // 8bye.. java 변수 예제 public class Main { public static void main(String[] args) { // variable(변수) : 프로그램 실행에 필요한 데이터를 저장하기 위해 // 메모리에 공간을 할당하고 이름을 부여한 것 // [변수타입] [변수명] = [변수값]; int a = 10; // 변수 선언 + 초기화 int b; // 변수 선언 b = 10; // 변수 초기화 // 같은 데이터 타입일 때 int c, d, e, f; // 다중선언 int g = 1, h = 2, i = 3; // 다중선언과 초기화 // 1byte = 8bit; System.out.println("a+b = " + (a + b)); } } 실행결과 설명 변수(variable) 프로그램 실행에 필요한 데이터를.. 이전 1 2 3 다음