Search

์ค‘์ฒฉ if ๋ฌธ

import java.util.Scanner; public class Ex04_Nested { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // ์ •๋ณด์ฒ˜๋ฆฌ๊ธฐ์‚ฌ ํ•ฉ๊ฒฉ ๊ธฐ์ค€ // (์กฐ๊ฑด) 4ํ•™๋…„, 60์  ์ด์ƒ System.out.print("ํ•™๋…„ : "); int year = sc.nextInt(); System.out.print("์ ์ˆ˜ : "); int score = sc.nextInt(); // ** ์ค‘์ฒฉ if๋ฌธ ๊ถŒ์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. // 4ํ•™๋…„ if( year == 4 ) { // 60์  ์ด์ƒ if( score >= 60 ) { System.out.println("ํ•ฉ๊ฒฉ!"); } else { System.out.println("๋ถˆํ•ฉ๊ฒฉ!"); } } else { System.out.println("์‘์‹œ์ž๊ฒฉ์ด ์—†์Šต๋‹ˆ๋‹ค."); } // ์กฐ๊ฑด๋ฌธ(if)๋ฌธ์„ ์ค‘์ฒฉํ•˜์ง€ ์•Š๊ณ  ์กฐ๊ฑด์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. // ๋ฐฉ๋ฒ•1 if( year == 4 && score >= 60 ) System.out.println("ํ•ฉ๊ฒฉ!"); else if( year == 4 ) System.out.println("๋ถˆํ•ฉ๊ฒฉ!"); else System.out.println("์‘์‹œ์ž๊ฒฉ์ด ์—†์Šต๋‹ˆ๋‹ค."); // ๋ฐฉ๋ฒ•2 if( year != 4 ) System.out.println("์‘์‹œ์ž๊ฒฉ์ด ์—†์Šต๋‹ˆ๋‹ค."); else if ( score >= 60 ) System.out.println("ํ•ฉ๊ฒฉ!"); else System.out.println("๋ถˆํ•ฉ๊ฒฉ!"); sc.close(); } }
Java
๋ณต์‚ฌ