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

๐Ÿ“œ ์ž๋ฐ” Java25

์ž๋ฐ”(JAVA) - ์ดˆ๊ธฐํ™”์™€ ์ƒ์„ฑ์ž Constructor Constructor : ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ํด๋ž˜์Šค๋ช…๊ณผ ๊ฐ™๋‹ค return๊ฐ’์ด ์—†๋‹ค. Over Load๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. class ์ƒ์„ฑ์‹œ์— ์ž๋™ํ˜ธ์ถœ ๋ณ„๋„์˜ ํ˜ธ์ถœ์ด ๋ถˆ๊ฐ€๋Šฅ ์ดˆ๊ธฐํ™” ์•ˆ๋œ๋‹ค ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•˜๋‹ค 1. ๋ฆฌํ„ด๊ฐ’์ด ์—†๋‹ค. ์ƒ์„ฑ์ž๋Š” ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๋Š” ์—ญํ• ์„ ํ•˜๋Š” ํŠน์ˆ˜ํ•œ ๋ฉ”์†Œ๋“œ๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ๋ฐ˜ํ™˜ ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ์—‰๋šฑํ•œ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋  ๊ฒƒ์ด๋‹ค. ๋”ฐ๋ผ์„œ ๋ฐ˜ํ™˜ ๊ฐ’์„ ํ•„์š”๋กœํ•˜๋Š” ์ž‘์—…์—์„œ๋Š” ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋ฐ˜ํ™˜ ๊ฐ’์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— return๋„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ๋ฐ˜ํ™˜ ๊ฐ’์„ ๋ฉ”์†Œ๋“œ ์ •์˜์— ํฌํ•จ์‹œํ‚ค์ง€๋„ ์•Š๋Š”๋‹ค. 2. ์ƒ์„ฑ์ž์˜ ์ด๋ฆ„์€ ํด๋ž˜์Šค์˜ ์ด๋ฆ„๊ณผ ๊ฐ™๋‹ค. ์ž๋ฐ”์—์„œ ํด๋ž˜์Šค์˜ ์ด๋ฆ„๊ณผ ๋™์ผํ•œ ๋ฉ”์†Œ๋“œ๋Š” ์ƒ์„ฑ์ž๋กœ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ์•ฝ์†๋˜์–ด ์žˆ๋‹ค. 12345678910111213141516171819202122232425262728.. 2021. 1. 27.
์ž๋ฐ”(JAVA) - ๋‘ ์ฃผ์‚ฌ์œ„ ํ•ฉ ๋งž์ถ”๊ธฐ, ๋ฒ ํŒ…๊ฒŒ์ž„ 123456789101112 public class MainClass { public static void main(String[] args) { // TODO Auto-generated method stub GamePlay gp = new GamePlay (); gp.gamePlay(); } }Colored by Color Scriptercs 123456789101112131415public class Dice { private int number; public void diceRandom() { number = (int)(Math.random()*6)+1; } public int getNumber() { return number; } } Colored by Color Scriptercs 1234567.. 2021. 1. 26.
์ž๋ฐ”(JAVA) - TV ์ „์›, ๋ณผ๋ฅจ, ์ฑ„๋„ ๋ฆฌ๋ชจ์ปจ ํ”„๋กœ๊ทธ๋ž˜๋ฐ 123456789101112131415161718192021 public class MainClass { public static void main(String[] args) { Mytv2 t = new Mytv2(); t.setChannel(10); System.out.println("CH:" + t.getChannel()); t.setVolume(20); System.out.println("VOL" + t.getVolume()); } } Colored by Color Scriptercs 123456789101112131415161718192021222324252627282930313233343536373839public class Mytv2 { private boolean isPowerOn; priv.. 2021. 1. 26.
์ž๋ฐ”(JAVA) - ํ•™์ƒ ์„ฑ์  ๊ฐ์ฒดํ™” ํ”„๋กœ๊ทธ๋ž˜๋ฐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import java.util.Scanner; public class Student { Scanner sc = new Scanner(System.in); String name; //ํ•™์ƒ์ด๋ฆ„ int ban; //๋ฐ˜ int no; //๋ฒˆํ˜ธ int kor; //๊ตญ์–ด์ ์ˆ˜ int eng; //์˜์–ด์ ์ˆ˜ int math; //์ˆ˜ํ•™์ ์ˆ˜ int getTotal() { return kor + eng + math;} float getAverage() { return (((getTotal()*100/3+5)/10)/10f); } } Colored by Color Scripter cs 1 2 3 4 5 6 7 8 9 10 11 12.. 2021. 1. 26.