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

[Java-๊ธฐ์ดˆ] ์‹ค์Šต (๋ฉ”์„œ๋“œ๋กœ ๊ตฌ๊ตฌ๋‹จ ํ˜ธ์ถœํ•˜๊ธฐ)

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 24.
๋ฐ˜์‘ํ˜•

์‹ค์Šต) ๊ตฌ๊ตฌ๋‹จ์„ ๋งŒ๋“ค์–ด๋ณด์‹œ์˜ค.

์กฐ๊ฑด : ๋ฉ”์„œ๋“œ๋กœ ํ˜ธ์ถœํ•˜๊ธฐ

 

โ€‹

 

<๋‚ด๊ฐ€ ํ•œ ๊ฒƒ>

โ€‹

ProgTest1.java

package quiz;

import java.util.Scanner;

public class ProgTest1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("๋ช‡๋‹จ์„ ๋ณด์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
		int n = sc.nextInt();
		int dan, times;

		System.out.println(n + "๋‹จ :");
		for (dan = n; dan <= n; dan++) {
			for (times = 1; times <= 9; times++) {
				System.out.print(n + "*" + times + "=" + n * times + " ");
			}
		}
	}
}

<๊ฒฐ๊ณผ๊ฐ’>

-์ผ๋‹จ ๋ฉ”์„œ๋“œ๋กœ ํ˜ธ์ถœํ•˜๋Š”๊ฑฐ ๋ง๊ณ  ์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด๋ดค๋‹ค

๋ฉ”์„œ๋“œ๋กœ ๋งŒ๋“œ๋Š”๊ฑด ์‹คํŒจ!

โ€‹

โ€‹

 

ProgTest2.java

package quiz;

import java.util.Scanner;

public class ProgTest2 {
	public int cVar = 0;
	String[] iStr = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
	double iDouble;
	boolean iBool = false;
	char iChar = 'a';

	String getGugugan(int dan) {
		String str = dan + "๋‹จ:\n";
		for (int i = 1; i < 10; i++) {
			str += dan + "*" + i + "=" + (dan * i) + "\t";
		}
		return str;
	}

	public static void main(String[] args) {
		ProgTest2 pt2 = new ProgTest2();
		Scanner sc = new Scanner(System.in);
		System.out.print("๋ช‡๋‹จ์„ ๋ณด์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ");
		int dan = sc.nextInt();
		System.out.println(pt2.getGugugan(dan));
	}
}

<๊ฒฐ๊ณผ๊ฐ’>

-๋ฉ”์„œ๋“œ๋กœ ์ •์˜ํ•ด์„œ ํ˜ธ์ถœํ•˜๋Š”๊ฒŒ ์ข€ ์–ด๋ ค์› ๋‹ค (๋งจ๋‚  get, set ์ด๋Ÿฐ๊ฑฐ๋งŒ ํ•ด์„œ ๊ทธ๋Ÿฐ๋“ฏ)

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€