Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Everything has an expiration date

029 - Java 삼항 연산자 : 알파벳 변환 프로그램 내 풀이 본문

[Java]/Program source (java)

029 - Java 삼항 연산자 : 알파벳 변환 프로그램 내 풀이

Jelly-fish 2023. 8. 29. 13:48
// ============[알파벳 대소문자 변환 프로그램 내 풀이!!]===============


import java.io.IOException;

public class Mytest2
{
	public static void main(String[] args) throws IOException
	{
		int n, resultNum;

		char inputCh, resultCh;
		
		System.out.print("한 문자 입력 : ");

		n = System.in.read();
		inputCh = (char)n;

		

				//resultNum = ((65 <= n) && (n <= 90)) || ((97 <= n) && (n <= 122)) ? "알파벳" : "알파벳 아님";
				//																	 ----------
				//										                     (97 <= n) && (n <= 122) ? (n - 32) : (n + 32)


				
				//resultNum = ((65 <= n) && (n <= 90)) || ((97 <= n) && (n <= 122)) ? "알파벳" : "알파벳 아님";
				//																				 --------------
				//																					   n


		resultNum = ((65 <= n) && (n <= 90)) || ((97 <= n) && (n <= 122)) ? (((97 <= n) && (n <= 122)) ? (n - 32) : (n + 32)) : n;
		//																	-------------------------------------------------
		//																	   입력 문자 알파벳일 때 실행 (소문자인지 판별)
		//																							                           ----
		//																												  알파벳이 아님

		//resultNum = ((65 <= n) && (n <= 90)) || ((97 <= n) && (n <= 122)) ? (((97 <= n) && (n <= 122)) ? (n - 32) : (n + 32)) : n;
		//			  -----------------------------------------------------   -------------------------------------------------  ---                             
		//										1												      2							  3
		//																	   

		resultCh = (char)resultNum;

		System.out.printf("%c → %c%n", inputCh, resultCh);
		
	
	}
}