자바(443)
-
SwitchEx04.java-switch()문을 이용하여 사직 연산 수행
switch()문을 이용하여 사직 연산 수행 JDK ver7.0부터 switch()문에 인자값으로 문자열 전달 가능 소스코드 public class SwitchEx04 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int first =0, second=0, total=0; String operator; System.out.print("첫번째 숫자를 입력하세요 > "); first = input.nextInt(); System.out.print("두번째 숫자를 입력하세요 > "); second = input.nextInt(); System.out.print("수행할 연산..
-
SwitchEx02.java-switch문에 문자 비교
switch문에 문자 비교 소스코드 public class SwitchEx02 { public static void main(String[] args) { //char a = 'A'; //char a = 'B'; char a = 'C'; //char a ='D'; switch(a){ //char -> int 형변환 됨(아스키 코드로 인식됨) case 'A': System.out.println("A 출력하였습니다."); break; case 'B': System.out.println("B 출력하였습니다."); break; case 'C': System.out.println("C 출력하였습니다."); break; default: System.out.println("A, B, C가 아닌 문자 입니다."); }..
-
Error-Problems occurred while trying to save the state of the workbench
오류메시지 Problems occurred while trying to save the state of the workbench. Could not write metadata for '/.org.eclipse.jdt.core.external.folders'. C:\javanAndroid\workspace_android\.metadata\.plugins\org.eclipse.core.resources\.projects\.org.eclipse.jdt.core.external.folders\.markers (지정된 경로를 찾을 수 없습니다) 해결방법 workspace폴더안의 .metadata 폴더 삭제 후 이클립스 재시작
-
SwitchEx01.java-switch문에서 정수 비교하기
switch문에서 정수 비교하기 소스코드 출력결과 소스코드 public class SwitchEx01 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int a; System.out.print("정수형 숫자를 입력하세요 > "); a = input.nextInt(); switch(a){// JDK v6: long을 제외한 정수형(byte, short, int), char case 1: System.out.println("1 입력하였습니다."); break; case 2: System.out.println("2 입력하였습니다."); break; case 3: System...
-
IfEx02.java-단일 if
조건문 - 단일 if (정수형 입력 받은 후 짝수 홀수 구분하기) 소스코드 public class IfEx02 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int a; System.out.print("정수형 데이터 하나를 입력 > "); a = input.nextInt(); if(a%2 == 1){ //홀수 체크 System.out.print("홀수 입니다."); }else{ // 짝수 System.out.print("짝수 입니다."); } } } 출력결과
-
IfEx01.java-조건문 - 단일 If문
조건문 - 단일 If문 소스코드 public class IfEx01 { public static void main(String[] args) { int n =10; // int n =4; if( n > 5){ System.out.println("n은 5보다 크다"); } System.out.println("프로그램 종료"); } } 출력결과 n=4인 경우 n=10인 경우