๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป ํ”„๋กœ๊ทธ๋ž˜๋ฐ/JAVA

2-5 ํ”„๋กœ๊ทธ๋žจ๋„์ค‘ ํ‚ค๋ณด๋“œ ์ž…๋ ฅ๊ฐ’ ๋ฐ›๊ธฐ



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pack;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Test5io {
 
    public static void main(String[] args) throws Exception{ 
        // ํ”„๋กœ๊ทธ๋žจ ์ง„ํ–‰ ๋„์ค‘ ์™ธ๋ถ€์—์„œ ๊ฐ’ ์–ป๊ธฐ (์ž…์ถœ๋ ฅ)
        if(args.length == 0){
            System.out.println("์™ธ๋ถ€์—์„œ ๊ฐ’ ์–ป๊ธฐ ์‹คํŒจ!");
            System.exit(0); //์‘์šฉํ”„๋กœ๊ทธ๋žจ์˜ ๊ฐ•์ œ๋กœ ๋ฌด์กฐ๊ฑด์  ์ข…๋ฃŒ
        }
        
        System.out.println("์™ธ๋ถ€์—์„œ ์–ป์€ ๊ฐ’: " + args[0]);
        
        System.out.println("\nํ”„๋กœ๊ทธ๋žจ ์ง„ํ–‰ ๋„์ค‘ ํ‚ค๋ณด๋“œ๋กœ ๋ถ€ํ„ฐ ๊ฐ’ ์–ป๊ธฐ");
        System.out.print("๋ฌธ์ž ์ž…๋ ฅ:");
        int ch = System.in.read(); //ASCII ์ฝ”๋“œ ๊ฐ’ ์ž…๋ ฅ 'a' vs. "a"
        System.out.println("ch: " + ch + " " + (char)ch);
        
        System.in.read(); // Enterํ‚ค ์ฒ˜๋ฆฌ
        System.in.read();
        
        //ํ‚ค๋ณด๋“œ์—์„œ ๋ฌธ์ž์—ด ์–ป๊ธฐ
        BufferedReader buf =  new BufferedReader(new InputStreamReader(System.in));
        System.out.print("์ด๋ฆ„ ์ž…๋ ฅ:");
        String irum = buf.readLine();
        System.out.print("๋‚˜์ด ์ž…๋ ฅ:");
        String nai = buf.readLine();
        System.out.println("์ด๋ฆ„์€: " + irum + " ๋‹ˆ ๋‚˜์ด๋Š” :" + nai +"์‚ด");
        
        //ํ‚ค๋ณด๋“œ์—์„œ ๋ฌธ์ž์—ด ์–ป๊ธฐ2
        System.out.println("\n์Šค์บ๋„ˆ ํด๋ž˜์Šค ์‚ฌ์šฉ------------");
        Scanner sc = new Scanner(System.in);
        System.out.print("์ƒํ’ˆ ์ž…๋ ฅ:");
        String product = sc.next();
        System.out.print("๊ฐ€๊ฒฉ ์ž…๋ ฅ:");
        int price = sc.nextInt();
        System.out.println("์ƒํ’ˆ์€: " + product + "์˜ ๊ฐ€๊ฒฉ์€ " + price + " ์› ์ž…๋‹ˆ๋‹ค.");
        
        System.out.println("์ฒ˜๋ฆฌ ์™„๋ฃŒ");
 
    }
 
}
 
cs


๋ฐ˜์‘ํ˜•