/* ÀÌ ¼Ò½º ÆÄÀÏÀº WinApiÀÇ ÀÚ¹Ù °­Á¿¡¼­ ÀÛ¼ºÇÑ ¿¹Á¦µéÀÔ´Ï´Ù. °¢ ¿¹Á¦º°·Î ÁÖ¼® 󸮵Ǿî ÀÖÀ¸¹Ç·Î ÁÖ¼® ½ÃÀÛ À§Ä¡¿¡ /¸¦ Çϳª ´õ »ðÀÔÇÏ¿© ÁÖ¼®À» Ǭ ÈÄ ½ÇÇàÇØ º¸½Ã¸é µË´Ï´Ù. */ ///////////////////////////////////////////////////////////////////// //1Àå. ÀÚ¹Ù /* ù ¹ø° ¿¹Á¦ public class JavaExam { public static void main(String[] args) { System.out.println("Java Example Program"); } } //*/ /* print¿Í println class JavaExam { public static void main(String args[]) { System.out.println("One"); System.out.println("Two"); System.out.print("One"); System.out.print("Two"); } } //*/ /* ¿©·¯ °³ÀÇ º¯¼ö ÇѲ¨¹ø¿¡ Ãâ·ÂÇϱâ class JavaExam { public static void main(String args[]) { int i = 123; double d = 3.14; String str = "¹®ÀÚ¿­"; System.out.println("i = " + i + ", d = " + d + ", str = " + str); } } //*/ /* printf class JavaExam { public static void main(String args[]) { int i = 123; double d = 3.14; String str = "¹®ÀÚ¿­"; System.out.printf("i = %d, d = %f, str = %s\n", i, d, str); System.out.printf("i = %3$d, d = %2$f, str = %1$s\n", str, d, i, d); System.out.printf("__%5d__%-5d__%05d__%8.2f__\n", i, i, i, d); } } //*/ /* ¹®ÀÚ ´ÜÀ§ ÀÔ·Â - ¹ÙÀÌÆ® ½ºÆ®¸²À̶ó ÇѱÛÀº ¾ÈµÊ import java.io.*; class JavaExam { public static void main(String args[]) { int name; System.out.println("À̸§À» ÀÔ·ÂÇÑ ÈÄ Enter¸¦ ´©¸£½Ã¿À(³¡³¾ ¶§´Â Ctrl+Z)."); for (;;) { try { name = System.in.read(); if (name == -1) break; System.out.print((char)name); } catch (IOException e) { System.out.println("input error"); } } System.out.println("ÀԷ¿Ϸá"); } } //*/ /* ¹®ÀÚ ´ÜÀ§ ÀÔ·Â - Çѱ۵µ °¡´É import java.io.*; class JavaExam { public static void main(String args[]) { int name; System.out.println("À̸§À» ÀÔ·ÂÇÑ ÈÄ Enter¸¦ ´©¸£½Ã¿À(³¡³¾ ¶§´Â Ctrl+Z)."); InputStreamReader r = new InputStreamReader(System.in); for (;;) { try { name = r.read(); if (name == -1) break; System.out.print((char)name); } catch (java.io.IOException e) { System.out.println("input error"); } } System.out.println("ÀԷ¿Ϸá"); } } //*/ /* ÁÙ ´ÜÀ§ ÀÔ·Â import java.io.*; class JavaExam { public static void main(String args[]) { InputStreamReader r = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(r); try { String str = b.readLine(); System.out.println(str); System.out.println("ÀԷ¿Ϸá"); } catch (IOException e) { System.out.println("input error"); } } } //*/ /* Á¤¼ö¸¦ ÀԷ¹޾Ƽ­ 2¹èÇÏ¿© Ãâ·ÂÇϱâ import java.io.*; class JavaExam { public static void main(String args[]) { System.out.print("Á¤¼ö¸¦ ÀÔ·ÂÇϽÿÀ : "); InputStreamReader r = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(r); try { String str = b.readLine(); int i = Integer.parseInt(str); System.out.println("ÀԷ°ªÀÇ 2¹è = " + i*2); } catch (IOException e) { System.out.println("input error"); } } } //*/ ///////////////////////////////////////////////////////////////////// //2Àå. ±âº» ¹®¹ý /* º¯¼ö ¼±¾ð ¹× ´ëÀÔ class JavaExam { public static void main(String args[]) { int value; value = 1234; System.out.println(value); } } //*/ /* ºÎµ¿ ¼Ò¼öÁ¡ÀÇ ¿ÀÂ÷ class JavaExam { public static void main(String args[]) { float f = 0f; for (int i = 0; i < 1000; i++) { f += 0.1f; } System.out.println(f); } } //*/ /* ÁøÀ§Çü º¯¼ö class JavaExam { public static void main(String args[]) { int a = 3; boolean b = (a == 3); if (b) { System.out.println("a°¡ 3ÀÌ´Ù."); } } } //*/ /* ¹®ÀÚÇü º¯¼ö class JavaExam { public static void main(String args[]) { char ch = 'ÇÑ'; System.out.println(ch); //short s = ch; int i = ch; } } //*/ /* ¹®ÀÚ¿­ º¯¼ö class JavaExam { public static void main(String args[]) { String str = "¾Æ¸§´Ù¿î À̶¥¿¡ ±Ý¼ö°­»ê¿¡\n" + "´Ü±º ÇҾƹöÁö°¡ \"ÅÍ\"ÀâÀ¸½Ã°í"; for (int i = 0; i < str.length(); i++) { System.out.print(str.charAt(i)); } } } //*/ /* ¹è¿­ ¼±¾ð ¹× »ç¿ë class JavaExam { public static void main(String args[]) { int[] ar; ar = new int[10]; for (int i =0;i<5;i++) { ar[i]=i*2; System.out.println(ar[i]); } } } //*/ /* ¹è¿­ ÃʱâÈ­ class JavaExam { public static void main(String args[]) { int[] ar = { 8, 9, 0, 6, 2 }; //for (int i =0;i<5;i++) { for (int i =0;i= 19) { System.out.println("´ç½ÅÀº ¼ºÀÎÀÔ´Ï´Ù."); } else { System.out.println("¾ÖµéÀº °¡¶ó."); } } } //*/ /* for¹®À¸·Î ÇÕ°è ±¸Çϱâ class JavaExam { public static void main(String args[]) { int sum = 0; for (int i = 1; i <= 100; i++){ sum += i; } System.out.println(sum); } } //*/ /* ¿øÁÖÀ² ±¸Çϱâ class JavaExam { public static void main(String args[]) { double pie=0; int mother; double sign=1.0; for (mother=1;mother < 1000000;mother+=2) { pie += (1.0/mother)*sign; sign = -sign; } pie *= 4; System.out.println("pie = " + pie); } } //*/ /* for¹®ÀÇ Á¦¾î º¯¼ö - ¿¡·¯ ó¸®µÊ class JavaExam { public static void main(String args[]) { int i = 10; for (int i = 0; i <= 5; i++) { System.out.println("·çÇÁ ½ÇÇàÁß"); } System.out.println("i = " + i); } } //*/ /* µÎ °³ÀÇ Á¦¾î º¯¼ö class JavaExam { public static void main(String args[]) { for (int i = 0, j = 1; i < 5; i++, j += 2){ System.out.printf("i = %d, j = %d\n", i, j); } } } //*/ /* ¹è¿­ ¼øȸ class JavaExam { public static void main(String args[]) { int[] ar = { 8, 9, 0, 6, 2 }; for (int i : ar) { System.out.println(i); } } } //*/ /* while ¹®À¸·Î ÇÕ°è ±¸Çϱâ class JavaExam { public static void main(String args[]) { int sum = 0; int i = 1; while (i <= 100) { sum += i; i++; } System.out.println(sum); } } //*/ /* do while ¹®À¸·Î ÇÕ°è ±¸Çϱâ class JavaExam { public static void main(String args[]) { int sum = 0; int i = 1; do { sum += i; i++; } while (i <= 100); System.out.println(sum); } } //*/ /* ¹«ÇÑ ·çÇÁ¿Í break·Î ÃÖ¼Ò °ø¹è¼ö ã±â class JavaExam { public static void main(String args[]) { int a = 6; int b = 8; int k = 1; for (;;) { if (k % a == 0 && k % b == 0) { break; } k++; } System.out.printf("%d¿Í %dÀÇ ÃÖ¼Ò °ø¹è¼ö = %d", a, b, k); } } //*/ /* ÀÌÁß ·çÇÁ Å»Ãâ class JavaExam { public static void main(String args[]) { outer: for (int i = 0; i < 3 ; i++) { for (int j = 0; j < 3; j++) { if (i == 1 && j == 1) break outer; System.out.println("i = " + i + ", j = " + j); } } } } //*/ /* switch ¹® class JavaExam { public static void main(String args[]) { int num = 3; switch (num) { case 1: System.out.println("Çϳª"); break; case 2: System.out.println("µÑ"); break; case 3: System.out.println("¼Â"); break; case 4: System.out.println("³Ý"); break; case 5: System.out.println("´Ù¼¸"); break; default: System.out.println("±× ¿ÜÀÇ ¼ýÀÚ"); break; } } } //*/ /* »çÄ¢ ¿¬»ê class JavaExam { public static void main(String args[]) { int a = 4, b = 3; System.out.printf("%d + %d = %d\n", a, b, a + b); System.out.printf("%d - %d = %d\n", a, b, a - b); System.out.printf("%d * %d = %d\n", a, b, a * b); System.out.printf("%d / %d = %d\n", a, b, a / b); System.out.printf("%d / %d = %f\n", a, b, (double)a / b); System.out.printf("%d %% %d = %d\n", a, b, a % b); System.out.printf("%f %% %f = %f\n", 5.0, 2.3, 5.0 % 2.3); } } //*/ /* ¹®ÀÚ¿­ ¿¬°á class JavaExam { public static void main(String args[]) { System.out.println(12 + 34); System.out.println("miss" + "kim"); System.out.println("miss" + 12); System.out.println(12 + "miss"); System.out.println("miss" + 12 + 34); System.out.println(12 + 34 + "miss"); System.out.println("" + 12 + 34 + "miss"); } } //*/ /* »ïÇ× Á¶°Ç ¿¬»êÀÚ class JavaExam { public static void main(String args[]) { int a = -3; int absa = (a > 0 ? a:-a); System.out.println(absa); System.out.println(a == 3 ? 3:"3ÀÌ ¾Æ´Ô"); } } //*/ /* Áõ°¡ ¿¬»êÀÚ class JavaExam { public static void main(String args[]) { int a = 3; System.out.println(a++); System.out.println(++a); } } //*/ /* ºñ±³ ¿¬»êÀÚ¿Í ³í¸® ¿¬»êÀÚ class JavaExam { public static void main(String args[]) { int a = 1, b = 2; if (a == 1 && b == 2) { System.out.println("OK1"); } if (a != 1 || b == 3) { System.out.println("OK2"); } if (a > 1 && b == 2) { System.out.println("OK3"); } } } //*/ ///////////////////////////////////////////////////////////////////// //3Àå.Ŭ·¡½º /* Car Ŭ·¡½º class Car { String Name; String Color; boolean Gasoline; void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class JavaExam { public static void main(String args[]) { Car Pride = new Car(); Pride.Name = "ÇÁ¶óÀ̵å"; Pride.Color = "ÆĶû"; Pride.Gasoline = true; Pride.Run(); Pride.Stop(); } } //*/ /* ¸Þ¼Òµå ¿À¹ö·Îµù class Adder { static int Add(int a, int b) { return a + b; } static int Add(int a, int b, int c) { return a + b + c; } static double Add(double a, double b) { return a + b; } //long Add(int a, int b) { return (long)(a + b); } } class JavaExam { public static void main(String args[]) { System.out.println(Adder.Add(1,2)); System.out.println(Adder.Add(1,2,3)); System.out.println(Adder.Add(1.2,3.4)); } } //*/ /* °¡º¯Àμö class Adder { static int Add(int ... a) { int sum = 0; for (int i=0;i 2000) { ModelYear = aModelYear; } } } class JavaExam { public static void main(String args[]) { Car Pride = new Car(); Pride.Name = "ÇÁ¶óÀ̵å"; Pride.Color = "ÆĶû"; Pride.Gasoline = true; //Pride.ModelYear=2005; Pride.SetModelYear(2005); System.out.println(Pride.GetModelYear()); } } //*/ /* Á¤Àû Çʵå class Car { String Name; static int CarNum = 0; Car(String aName) { Name = aName; CarNum++; } } class JavaExam { public static void main(String args[]) { Car Pride = new Car("ÇÁ¶ûÀÌ"); Car Matis = new Car("¸¶ÆÃÀÌ"); Car Carnival = new Car("´Ï¹ßÀÌ"); System.out.println("Â÷ " + Car.CarNum + "´ë ±¸ÀÔÇß´Ù."); } } //*/ /* Á¤Àû ÃʱâÈ­ ºí·Ï class Sales { static int[] table; static { table = new int[10]; for (int i = 0; i < table.length; i++) { table[i] = i*2; } } } class JavaExam { public static void main(String args[]) { Sales sales = new Sales(); System.out.println(Sales.table[2]); } } //*/ /* Á¤Àû ¸Þ¼Òµå class Hello { static void Morning() { System.out.println("ÁÁÀº ¾Æħ"); } static void Lunch() { System.out.println("Á¡½É ¸Ô¾ú¾î?"); } static void Evening() { System.out.println("¼ú ÇÑÀÜ ¾î¶§"); } } class JavaExam { public static void main(String args[]) { Hello.Morning(); Hello.Lunch(); Hello.Evening(); } } //*/ /* Á¤Àû Çʵå¿Í Á¤Àû ¸Þ¼Òµå class Statistics { static int[] Info; double ratio = 1.5; static { Info = new int[10]; Info[0] = 1415; Info[1] = 9265; Info[2] = 3589; } static int GetAverage() { int sum = 0; for (int i : Info) { sum += i; } //sum *= ratio; return sum/Info.length; } double GetSomeValue(double input) { return input * ratio * GetAverage(); } } class JavaExam { public static void main(String args[]) { System.out.println(Statistics.GetAverage()); Statistics S = new Statistics(); System.out.println(S.GetSomeValue(3)); } } //*/ /* »ó¼ö Çʵå class Circle { static final double PIE = 3.14159265; double Radius; Circle(double aRadius) { Radius = aRadius; } double GetCircum() { return 2*Radius*PIE; } double GetArea() { return Radius*Radius*PIE; } } class JavaExam { public static void main(String args[]) { Circle C = new Circle(3); System.out.println("¿øÁÖ = " + C.GetCircum()); System.out.println("¸éÀû = " + C.GetArea()); } } //*/ /* »ý¼ºÀÚ¿¡¼­ ÃʱâÈ­ÇÏ´Â »ó¼ö Çʵå class NoteBook { final String CPU; int Memory; int HDD; NoteBook(String aCPU, int aMemory, int aHDD) { CPU = aCPU; Memory = aMemory; HDD = aHDD; } void UpgradeMemory(int aMemory, int aHDD) { Memory = aMemory; HDD = aHDD; // CPU = "Super Strong 8 Core 4.5GHz"; } void OutSpec() { System.out.printf("CPU = %S, Memory = %d, HDD= %d\n", CPU, Memory, HDD); } } class JavaExam { public static void main(String args[]) { NoteBook Sens = new NoteBook("Intel Q9000", 3, 500); NoteBook XNote = new NoteBook("AMD Sampron", 2, 320); Sens.OutSpec(); XNote.OutSpec(); Sens.UpgradeMemory(8,750); Sens.OutSpec(); } } //*/ /* ¿­°ÅÇü enum Race { TERRAN, ZERG, PROTOSS } class JavaExam { public static void main(String args[]) { Race MyTeam; // Race MyTeam = new Race(TERRAN); MyTeam = Race.ZERG; // MyTeam = 1; // int i = (int)MyTeam; System.out.println(MyTeam); for (Race R : Race.values()) { System.out.print(R+" "); } System.out.println(""); Race YourTeam = Race.valueOf("PROTOSS"); System.out.println(YourTeam); } } //*/ /* ¿­°ÅÇü¿¡ ´Ù¸¥ ŸÀÔÀÇ °ª ¿¬°áÇϱâ enum Race { TERRAN("Å׶õ"), ZERG("Àú±×"), PROTOSS("ÇÁ·ÎÅ佺"); final private String HanRace; Race(String Han) { HanRace = Han; } String getHanName() { return HanRace; } } class JavaExam { public static void main(String args[]) { Race MyTeam; MyTeam = Race.ZERG; System.out.println(MyTeam.getHanName()); } } //*/ /* Àڹ٠ŸÀÔ ¿­°ÅÇü enum JavaType { SHORT("ªÀº Á¤¼öÇü",2), INT("Á¤¼öÇü",4),DOUBLE("½Ç¼öÇü",8); final private String TypeName; final private int Length; JavaType(String Name, int Byte) { TypeName = Name; Length = Byte; } String getName() { return TypeName; } int getLength() { return Length; } } class JavaExam { public static void main(String args[]) { JavaType Type; Type = JavaType.INT; System.out.println("ŸÀÔ : " + Type + ", À̸§ : " + Type.getName() + ", ±æÀÌ : " + Type.getLength()); } } //*/ /* »ó¼Ó class Car { public String Name; protected String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class Truck extends Car { int Ton; Truck(String aName, String aColor, boolean aGasoline, int aTon) { super(aName,aColor,aGasoline); //ÀϺΠ¸â¹ö¸¦ ¼öÁ¤ °¡´É //super(aName,aColor,false); Ton = aTon; } void Run() { //½´ÆÛ Å¬·¡½ºÀÇ ¸Þ¼Òµå È£Ãâ. ²À óÀ½ÀÌ ¾Æ´Ï¾îµµ »ó°ü¾øÀ½ //super.Run(); System.out.println("¿ì´çÅÁ ÄôÅÁ"); } void Convey() { System.out.println("ÁüÀ» ½Ç¾î ³ª¸¥´Ù."); } } class JavaExam { public static void main(String args[]) { Truck Porter = new Truck("Æ÷ÅÍ", "Èò»ö", false, 1000); Porter.Run(); Porter.Convey(); } } //*/ /* ºÎ¸ð´Â ÀÚ½ÄÀ» °¡¸®Å²´Ù. class Car { public String Name; protected String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class Truck extends Car { int Ton; Truck(String aName, String aColor, boolean aGasoline, int aTon) { super(aName,aColor,aGasoline); Ton = aTon; } void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } void Convey() { System.out.println("ÁüÀ» ½Ç¾î ³ª¸¥´Ù."); } } class JavaExam { public static void main(String args[]) { Car MyCar = new Car("Á¦³×½Ã½º", "»¡°­", true); Car YourCar = new Truck("ºÀ°í", "ÆĶû", true, 1500); MyCar.Run(); YourCar.Run(); //YourCar.Convey(); //Truck MyTruck = new Car("Á¦³×½Ã½º", "»¡°­", true); //MyTruck.Run(); //MyTruck.Stop(); //MyTruck.Convey(); } } //*/ /* ´ÙÇü¼º class Car { public String Name; protected String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class Truck extends Car { int Ton; Truck(String aName, String aColor, boolean aGasoline, int aTon) { super(aName,aColor,aGasoline); Ton = aTon; } void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } void Convey() { System.out.println("ÁüÀ» ½Ç¾î ³ª¸¥´Ù."); } } class JavaExam { public static void TestCar(Car car) { car.Run(); car.Stop(); //car.Convey(); } public static void main(String args[]) { Car MyCar = new Car("Á¦³×½Ã½º", "»¡°­", true); Car YourCar = new Truck("ºÀ°í", "ÆĶû", true, 1500); TestCar(MyCar); TestCar(YourCar); } } //*/ /* °´Ã¼ ij½ºÆà class Car { public String Name; protected String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class Truck extends Car { int Ton; Truck(String aName, String aColor, boolean aGasoline, int aTon) { super(aName,aColor,aGasoline); Ton = aTon; } void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } void Convey() { System.out.println("ÁüÀ» ½Ç¾î ³ª¸¥´Ù."); } } class JavaExam { public static void main(String args[]) { Car MyTruck = new Truck("ºÀ°í", "ÆĶû", true, 1500); Truck AnyTruck; AnyTruck = (Truck)MyTruck; AnyTruck.Convey(); } } //*/ /* Ŭ·¡½º°£ÀÇ Ä³½ºÆ® ¿¬»ê class Car { public String Name; protected String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void Run() { if (Gasoline) { System.out.println("ºÎ¸ª ºÎ¸ª"); } else { System.out.println("´úÄÈ ´úÄÈ"); } } void Stop() { System.out.println("³¢ÀÌÀÍ"); } } class Truck extends Car { int Ton; Truck(String aName, String aColor, boolean aGasoline, int aTon) { super(aName,aColor,aGasoline); Ton = aTon; } void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } void Convey() { System.out.println("ÁüÀ» ½Ç¾î ³ª¸¥´Ù."); } } class JavaExam { public static void TestCar(Car car) { car.Run(); car.Stop(); if (car instanceof Truck) { Truck truck = (Truck)car; truck.Convey(); //((Truck)car).Convey(); } } public static void main(String args[]) { Car[] arCar = { new Car("±×·£Àú", "°ËÁ¤", true), new Truck("Æ÷ÅÍ", "ÆĶû", false, 1500), new Car("¼Ò³ªÅ¸", "ÇϾç", true), }; for (Car car: arCar) { TestCar(car); } } } //*/ /* Ãß»ó Ŭ·¡½º abstract class Dog { void SwingTail() { System.out.println("»ì¶û»ì¶û"); } abstract void Bark(); } class Jindo extends Dog { void Bark() { System.out.println("¸Û¸Û"); } } class Chihuahua extends Dog { void Bark() { System.out.println("¿Ð¿Ð"); } } class JavaExam { public static void main(String args[]) { Jindo Jindol = new Jindo(); Chihuahua Happy = new Chihuahua(); Jindol.Bark(); Happy.Bark(); } } //*/ /* ÀÎÅÍÆäÀ̽º interface Animal { void Eat(); void Sleep(); } class Cow implements Animal { public void Eat() { System.out.println("¿ì°Æ¿ì°Æ"); } public void Sleep() { System.out.println("ÄðÄð"); } } class JavaExam { public static void main(String args[]) { Cow So = new Cow(); So.Eat(); So.Sleep(); } } //*/ /* ´ÙÁß »ó¼Ó abstract class Dog { void SwingTail() { System.out.println("»ì¶û»ì¶û"); } abstract void Bark(); } interface Animal { void Eat(); void Sleep(); } class Chihuahua extends Dog implements Animal { void Bark() { System.out.println("¿Ð¿Ð"); } public void Eat() { System.out.println("³È³È³È³È"); } public void Sleep() { System.out.println("½Ø±Ù½Ø±Ù"); } } class JavaExam { public static void main(String args[]) { Chihuahua Happy = new Chihuahua(); Happy.SwingTail(); Happy.Bark(); Happy.Eat(); Happy.Sleep(); //Animal Ddaeng7 = new Chihuahua(); //Ddaeng7.Eat(); //Ddaeng7.Sleep(); } } //*/ /* Ŭ·¡½ºÀÇ Áßø class CarName { String Model; int Year; CarName(String aModel, int aYear) { Model = aModel; Year = aYear; } } class Car { CarName Name; String Color; Car(String aModel, int aYear,String aColor) { Name = new CarName(aModel,aYear); Color = aColor; } void OutInfo() { System.out.printf("¸ðµ¨ = %s, ³â½Ä = %d, »ö»ó = %s\n", Name.Model, Name.Year, Color); } } public class JavaExam { public static void main(String[] args) { Car Pride = new Car("ÇÁ¶óÀ̵å", 2005, "ÆĶû"); Pride.OutInfo(); CarName Grandeur = new CarName("±×·£´ÙÀÌÀú", 2009); System.out.printf("¸ðµ¨ = %s, ³â½Ä = %d\n", Grandeur.Model,Grandeur.Year); } } //*/ /* Á¤Àû ÀÌ³Ê Å¬·¡½º class Car { CarName Name; String Color; static class CarName { String Model; int Year; CarName(String aModel, int aYear) { Model = aModel; Year = aYear; } } Car(String aModel, int aYear,String aColor) { Name = new CarName(aModel,aYear); Color = aColor; } void OutInfo() { System.out.printf("¸ðµ¨ = %s, ³â½Ä = %d, »ö»ó = %s\n", Name.Model, Name.Year, Color); } } public class JavaExam { public static void main(String[] args) { Car Pride = new Car("ÇÁ¶óÀ̵å", 2005, "ÆĶû"); Pride.OutInfo(); Car.CarName Grandeur = new Car.CarName("±×·£´ÙÀÌÀú", 2009); System.out.printf("¸ðµ¨ = %s, ³â½Ä = %d\n", Grandeur.Model,Grandeur.Year); } } //*/ /* ÀÌ³Ê Å¬·¡½º class Car { CarName Name; String Color; class CarName { String Model; int Year; CarName(String aModel, int aYear) { Model = aModel; Year = aYear; } void OutColor() { System.out.println("»ö»óÀº " + Color + "ÀÔ´Ï´Ù."); } } Car(String aModel, int aYear,String aColor) { Name = new CarName(aModel,aYear); Color = aColor; } void OutInfo() { System.out.printf("¸ðµ¨ = %s, ³â½Ä = %d, »ö»ó = %s\n", Name.Model, Name.Year, Color); } } public class JavaExam { public static void main(String[] args) { Car Pride = new Car("ÇÁ¶óÀ̵å", 2005, "ÆĶû"); Pride.OutInfo(); Pride.Name.OutColor(); Car.CarName Pride2 = Pride.new CarName("ÇÁ¶ûÀÌ", 2009); Pride2.OutColor(); } } //*/ /* ·ÎÄà ÀÌ³Ê Å¬·¡½º public class JavaExam { public static void main(String[] args) { class Car { void Run() { System.out.println("ºÎ¸ª ºÎ¸ª"); } } Car Forte = new Car(); Forte.Run(); } } //*/ /* ¿ÜºÎ Ŭ·¡½º¸¦ »ó¼Ó¹Þ´Â ·ÎÄà ÀÌ³Ê Å¬·¡½º class Car { void Run() { System.out.println("ºÎ¸ª ºÎ¸ª"); } } public class JavaExam { public static void main(String[] args) { class Truck extends Car { void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } } Truck Porter = new Truck(); Porter.Run(); } } //*/ /* ÀÍ¸í ·ÎÄà ÀÌ³Ê Å¬·¡½º class Car { void Run() { System.out.println("ºÎ¸ª ºÎ¸ª"); } } public class JavaExam { public static void main(String[] args) { Car Porter = new Car() { void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } }; Porter.Run(); } } //*/ /* ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ´Â ÀÍ¸í ·ÎÄà ÀÌ³Ê Å¬·¡½º interface ICar { void Run(); } public class JavaExam { public static void main(String[] args) { ICar Porter = new ICar() { public void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } }; Porter.Run(); } } //*/ /* ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ´Â ÀÍ¸í ·ÎÄà ÀÌ³Ê Å¬·¡½º interface ICar { void Run(); } public class JavaExam { public static void main(String[] args) { class Anonymous implements ICar { public void Run() { System.out.println("¿ì´çÅÁ ÄôÅÁ"); } }; Anonymous Porter = new Anonymous(); Porter.Run(); } } //*/ ///////////////////////////////////////////////////////////////////// //4Àå.ÀÚ¹Ù ¶óÀ̺귯¸® /* PackageTest package kr.winapi; public class PackageTest { public static void main(String[] args) { kimutil.UtilClass.UtilMethod(); parkutil.UtilClass.UtilMethod(); } } //*/ /* kilutil.UtilClass.java package kimutil; public class UtilClass { public static void UtilMethod() { System.out.println("±èÂ÷ÀåÀÇ À¯Æ¿¸®Æ¼"); } } //*/ /* parkutil.UtilClass.java package parkutil; public class UtilClass { public static void UtilMethod() { System.out.println("¹Ú°úÀåÀÇ À¯Æ¿¸®Æ¼"); } } //*/ /* import package kr.winapi; import kimutil.UtilClass; public class PackageTest { public static void main(String[] args) { UtilClass.UtilMethod(); parkutil.UtilClass.UtilMethod(); } } //*/ /* toString class Car { String Name; String Color; Car(String aName, String aColor) { Name = aName; Color = aColor; } //public String toString() { return Color + " " + Name; } } class JavaExam { public static void main(String args[]) { int i = 1234; System.out.println(i); Car Pride = new Car("ÇÁ¶óÀ̵å", "ÆĶû"); System.out.println(Pride); } } //*/ /* equals class Car { String Name; Car(String aName) { Name = aName; } public boolean equals(Object obj) { if (obj instanceof Car) { Car other = (Car)obj; return (Name.equals(other.Name)); } return false; } } class JavaExam { public static void main(String args[]) { Car Pride = new Car("ÇÁ¶óÀ̵å"); Car Pride2 = new Car("ÇÁ¶óÀ̵å"); Car Cerato = new Car("¼¼¶óÅä"); Car PrideCopy = Pride; System.out.println(Pride == Pride2 ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(Pride == PrideCopy ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(Pride.equals(Pride2) ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(Pride.equals(Cerato) ? "°°´Ù":"´Ù¸£´Ù"); } } //*/ /* getClass import java.lang.reflect.*; class Car { String Name; String Color; boolean Gasoline; void Run() { } void Stop() { } } class JavaExam { public static void main(String args[]) { Car Pride = new Car(); Class cls = Pride.getClass(); //Class cls = Car.class; System.out.println("Ŭ·¡½º À̸§ = " + cls.getName()); System.out.println("½´ÆÛ Å¬·¡½º = " + cls.getSuperclass().getName()); Field[] fields = cls.getDeclaredFields(); System.out.print("Çʵå : "); for (Field F : fields) { System.out.print(F.getName() + " "); } System.out.print("\n¸Þ¼Òµå : "); Method methods[] = cls.getDeclaredMethods(); for (Method M : methods) { System.out.print(M.getName() + " "); } } } //*/ /* ¹Ú½Ì class JavaExam { public static void main(String args[]) { int i = 1234; String str; //str = i.toString(); Integer wrapint = new Integer(i); //Integer wrapint = i; //Integer wrapint = Integer.valueOf(i); str = wrapint.toString(); System.out.println(str); } } //*/ /* ¹®ÀÚ¿­·ÎºÎÅÍ ¹Ú½Ì class JavaExam { public static void main(String args[]) { Integer wrapint = new Integer("629"); String str = wrapint.toString(); int i = Integer.parseInt(str); System.out.println(i); String a = "12", b = "34"; System.out.println(a + b); System.out.println(Integer.parseInt(a) + Integer.parseInt(b)); } } //*/ /* ¾ð¹Ú½Ì class JavaExam { public static void main(String args[]) { Integer wrapint = new Integer(629); int i = wrapint.intValue(); System.out.println(i); Double wrapdouble = new Double("3.14"); int di = wrapdouble.intValue(); System.out.println(di); } } //*/ /* ·¡ÆÛÀÇ ±â´É class JavaExam { public static void main(String args[]) { System.out.printf("int ŸÀÔÀÇ Å©±â = %d, ÃÖ¼Ò°ª = %d, ÃÖ´ë°ª = %d\n", Integer.SIZE, Integer.MIN_VALUE, Integer.MAX_VALUE); System.out.printf("Double ŸÀÔÀÇ Å©±â = %d, Áö¼ö ÃÖ¼Ò°ª = %d, Áö¼ö ÃÖ´ë°ª = %d\n", Double.SIZE, Double.MIN_EXPONENT, Double.MAX_EXPONENT); System.out.println(Integer.toBinaryString(1234)); System.out.println(Integer.toBinaryString(Float.floatToRawIntBits(3.14f))); } } //*/ /* StringÀÇ »ý¼ºÀÚ public class JavaExam { public static void main(String[] args) { String str; str = "¾Æ¸§´Ù¿î"; System.out.println(str); String str2 = "¿ì¸®³ª¶ó"; System.out.println(str2); char[] ar = { 'k', 'o', 'r', 'e', 'a' }; String str3 = new String(ar); System.out.println(str3); System.out.println("´ëÇѹα¹".length()); } } //*/ /* ¹®ÀÚ¿­ ºñ±³ public class JavaExam { public static void main(String[] args) { String str1 = "James Gosling"; String str2 = "James Gosling"; String str3 = "James "; str3 += "Gosling"; String str4 = "james gosling"; System.out.println(str1 == str2 ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(str1 == str3 ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(str1.equals(str3) ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(str1.equals(str4) ? "°°´Ù":"´Ù¸£´Ù"); System.out.println(str1.equalsIgnoreCase(str4) ? "°°´Ù":"´Ù¸£´Ù"); String Apple = "Apple"; String Orange = "Orange"; int Result = Apple.compareTo(Orange); if (Result == 0) { System.out.println("°°´Ù"); } else if (Result < 0) { System.out.println("AppleÀÌ ´õ ¾ÕÂÊ"); } else if (Result > 0) { System.out.println("AppleÀÌ ´õ µÚÂÊ"); } } } //*/ /* ¹®ÀÚ¿­ °Ë»ö public class JavaExam { public static void main(String[] args) { String str = "String Search Method of String Class"; System.out.println("¾ÕÂÊ t = " + str.indexOf('t')); System.out.println("µÚÂÊ t = " + str.lastIndexOf('t')); System.out.println("¾ÕÂÊ z = " + str.indexOf('z')); System.out.println("¾ÕÂÊ String = " + str.indexOf("String")); System.out.println("µÚÂÊ String = " + str.lastIndexOf("String")); } } //*/ /* ¹®ÀÚ¿­ º¯°æ public class JavaExam { public static void main(String[] args) { String str = " Made In Korea "; System.out.println(str.toLowerCase()); System.out.println(str.toUpperCase()); System.out.println(str.trim()); str.toUpperCase(); String str2 = str.toUpperCase(); System.out.println(str); System.out.println(str2); String str3 = "µ¶µµ´Â ÀϺ»¶¥ÀÌ´Ù. ´ë¸¶µµ´Â ÀϺ»¶¥ÀÌ´Ù."; System.out.println(str3.replaceFirst("ÀϺ»", "Çѱ¹")); System.out.println(str3.replaceAll("ÀϺ»", "Çѱ¹")); } } //*/ /* ºÎºÐ ¹®ÀÚ¿­ ÃßÃâ public class JavaExam { public static void main(String[] args) { String str = "0123456789"; System.out.println(str.substring(3,7)); String name = "Á¦ À̸§Àº <¾Æ¹«°³>ÀÔ´Ï´Ù."; int st, ed; st = name.indexOf('<'); ed = name.indexOf('>'); System.out.println(name.substring(st+1,ed)); } } //*/ /* StringÀ¸·Î ¹®ÀÚ¿­ Á¶ÀÛ public class JavaExam { public static void main(String[] args) { String str = ""; for (int i = 0; i < 1000; i++) { for (char ch = 'A'; ch <= 'z'; ch ++) { str += ch; } str += '\n'; } System.out.println(str); } } //*/ /* StringBuilder·Î ¹®ÀÚ¿­ Á¶ÀÛ public class JavaExam { public static void main(String[] args) { StringBuilder str = new StringBuilder(); for (int i = 0; i < 1000; i++) { for (char ch = 'A'; ch <= 'z'; ch ++) { str.append(ch); } str.append('\n'); } System.out.println(str); } } //*/ /* ¼öÇà ½Ã°£ ÃøÁ¤ class JavaExam { public static void main(String args[]) { long start = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { System.out.println(i + "¹ø° ÁÙ"); } long end = System.currentTimeMillis(); System.out.println((end-start)/1000.0 + " ÃÊ °É¸²"); } } //*/ /* ³­¼ö »ý¼º import java.util.Random; class JavaExam { public static void main(String args[]) { Random R = new Random(); for (int i = 0; i < 10; i++) { System.out.println(R.nextInt(100)); System.out.println(3.14e-1); } } } //*/ /* ÇöÀç ½Ã°£ Ãâ·Â import java.util.*; class JavaExam { public static void main(String args[]) { GregorianCalendar C = new GregorianCalendar(); System.out.printf("%d³â %d¿ù %dÀÏ %s %d½Ã %dºÐ %dÃÊ", C.get(Calendar.YEAR), C.get(Calendar.MONTH), C.get(Calendar.DATE), C.get(Calendar.AM_PM) == Calendar.AM ? "¿ÀÀü":"¿ÀÈÄ", C.get(Calendar.HOUR), C.get(Calendar.MINUTE), C.get(Calendar.SECOND)); } } //*/ /* ArrayList import java.util.*; class JavaExam { public static void main(String args[]) { ArrayList arName = new ArrayList(); arName.add("ÀüµÎȯ"); arName.add("±è¿µ»ï"); arName.add("±è´ëÁß"); arName.add(1,"³ëÅ¿ì"); for (int i = 0;i < arName.size();i++) { System.out.println(arName.get(i)); } System.out.println("=========="); arName.remove(2); arName.set(2,"¿ø´õ°É½º"); for (int i = 0;i < arName.size();i++) { System.out.println(arName.get(i)); } if (arName.indexOf("³ëÅ¿ì") != -1) { System.out.println("ÀÖ´Ù"); } else { System.out.println("¾ø´Ù"); } } } //*/ /* ±âº»Çü¿¡ ´ëÇÑ ArrayList import java.util.*; class JavaExam { public static void main(String args[]) { ArrayList arNum = new ArrayList(); arNum.add(86); arNum.add(92); arNum.add(77); for (Integer i : arNum) { System.out.println(i); } } } //*/ /* LinkedList import java.util.*; class JavaExam { public static void main(String args[]) { LinkedList arName = new LinkedList(); arName.add("ÀüµÎȯ"); arName.add("±è¿µ»ï"); arName.add("±è´ëÁß"); arName.add(1,"³ëÅ¿ì"); //for (int i = 0;i < arName.size();i++) { // System.out.println(arName.get(i)); //} Iterator it = arName.iterator(); while (it.hasNext()) { System.out.println(it.next()); } // ³ú ÀÚ¹Ù 539 ÆäÀÌÁö¿¡ µÈ´Ù°í µÇ¾î Àִµ¥ ¾ÈµÊ //Iterator it = arName.iterator(); //for (String Name : it) { // System.out.println(Name); //} } } //*/ /* HashMap import java.util.*; class JavaExam { public static void main(String args[]) { HashMap Snack = new HashMap(); Snack.put("¿À¡¾î ¶¥Äá", 2500); Snack.put("ÁÒ¸®Æþ", 1900); Snack.put("Çֺ극ÀÌÅ©", 450); Snack.put("»©»©·Î", 900); String MySnack = "ÁÒ¸®Æþ"; System.out.println(MySnack + "ÀÇ °¡°ÝÀº " + Snack.get(MySnack)); } } //*/ ///////////////////////////////////////////////////////////////////// //5Àå.°í±Þ ¹®¹ý /* ¿¹¿Ü ó¸® public class JavaExam { public static void main(String[] args) { int[] ar= {1,2,3,4,5}; int index = 5; try { System.out.println(ar[index]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("÷ÀÚ°¡ ¹è¿­ ¹üÀ§¸¦ ³Ñ¾î¼¹½À´Ï´Ù."); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println("¿¬»êÀ» ¿Ï·áÇß½À´Ï´Ù."); } } //*/ /* üũµå ¿¹¿Ü public class JavaExam { public static void main(String[] args) { System.out.println("ÇÁ·Î±×·¥ ½ÃÀÛ"); try { Thread.sleep(3000); } catch (InterruptedException e) { System.out.println("¿¹¿Ü ¹ß»ý"); } System.out.println("ÇÁ·Î±×·¥ ³¡"); } } //*/ /* ¿¹¿Ü °´Ã¼ÀÇ ¸Þ¼Òµå public class JavaExam { public static void main(String[] args) { method(); } static void method() { submethod(); } static void submethod() { int i; int a = 3, b = 0; try { i = a / b; System.out.println(i); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } } //*/ /* ¿¹¿Ü ´øÁö±â public class JavaExam { public static void main(String[] args) { try { method(); } catch (Exception e) { System.out.println(e.getMessage()); } } static void method() throws Exception { throw new Exception("¹º°¡ À߸øµÆÀ½."); } } //*/ /* Thread »ó¼Ó public class JavaExam { public static void main(String[] args) { MyThread worker = new MyThread(); worker.start(); for (int num = 0;num < 20;num++) { try { Thread.sleep(50); } catch (InterruptedException e) { ; } System.out.print("Java "); } } } class MyThread extends Thread { public void run() { for (int num = 0;num < 20;num++) { try { Thread.sleep(30); } catch (InterruptedException e) { ; } System.out.print("ÀÚ¹Ù "); } } } //*/ /* Runnable ±¸Çö public class JavaExam { public static void main(String[] args) { MyRunnable MyRun = new MyRunnable(); Thread worker = new Thread(MyRun); worker.start(); for (int num = 0;num < 20;num++) { try { Thread.sleep(50); } catch (InterruptedException e) { ; } System.out.print("Java "); } } } class MyRunnable implements Runnable { public void run() { for (int num = 0;num < 20;num++) { try { Thread.sleep(30); } catch (InterruptedException e) { ; } System.out.print("ÀÚ¹Ù "); } } } //*/ /* RunnableÀ» »ç¿ëÇØ¾ß ÇÏ´Â °æ¿ì public class JavaExam { public static void main(String[] args) { MyRunnable MyRun = new MyRunnable(); Thread worker = new Thread(MyRun); worker.start(); for (int num = 0;num < 20;num++) { try { Thread.sleep(50); } catch (InterruptedException e) { ; } System.out.print("Java "); } } } class MyClass { public void PrintJava() { for (int num = 0;num < 20;num++) { try { Thread.sleep(30); } catch (InterruptedException e) { ; } System.out.print("ÀÚ¹Ù "); } } } class MyRunnable extends MyClass implements Runnable { public void run() { PrintJava(); } } //*/ /* Runnable ±¸Çö - À͸í ÀÌ³Ê Å¬·¡½º public class JavaExam { public static void main(String[] args) { Thread worker = new Thread(mRunnable); worker.start(); for (int num = 0;num < 20;num++) { try { Thread.sleep(50); } catch (InterruptedException e) { ; } System.out.print("Java "); } } static Runnable mRunnable = new Runnable() { public void run() { for (int num = 0;num < 20;num++) { try { Thread.sleep(30); } catch (InterruptedException e) { ; } System.out.print("ÀÚ¹Ù "); } } }; } //*/ /* Runnable ±¸Çö - ´õ °£´ÜÇÑ À͸í ÀÌ³Ê Å¬·¡½º °´Ã¼ public class JavaExam { public static void main(String[] args) { Thread worker = new Thread(new Runnable() { public void run() { for (int num = 0;num < 20;num++) { try { Thread.sleep(30); } catch (InterruptedException e) { ; } System.out.print("ÀÚ¹Ù "); } } }); worker.start(); for (int num = 0;num < 20;num++) { try { Thread.sleep(50); } catch (InterruptedException e) { ; } System.out.print("Java "); } } } //*/ /* °øÀ¯ °´Ã¼¸¦ ÅëÇÑ ½º·¹µå°£ÀÇ Åë½Å public class JavaExam { public static void main(String[] args) { Memory mem = new Memory(16); DownLoad down = new DownLoad(mem); Play play = new Play(mem); down.start(); play.start(); } } class Memory { int[] buffer; int size; int progress; Memory(int asize) { size = asize; buffer = new int[asize]; progress = 0; } } class DownLoad extends Thread { Memory mem; DownLoad(Memory amem) { mem = amem; } public void run() { for (int off = 0;off < mem.size;off++) { mem.buffer[off] = off; mem.progress = off + 1; try { Thread.sleep(200); } catch (InterruptedException e) { ; } } } } class Play extends Thread { Memory mem; Play(Memory amem) { mem = amem; } public void run() { for (;;) { for (int off = 0;off < mem.progress;off++) { System.out.print(mem.buffer[off] + " "); } System.out.println(); if (mem.progress == mem.size) break; try { Thread.sleep(500); } catch (InterruptedException e) { ; } } } } //*/ /* µ¿±âÈ­ - µÎ ûũ°¡ ÇÑ ºí·ÏÀ» ±¸¼ºÇØ¾ß ÇÑ´Ù. public class JavaExam { public static void main(String[] args) { Memory mem = new Memory(16); DownLoad down = new DownLoad(mem); Play play = new Play(mem); down.start(); play.start(); } } class Memory { int[] buffer; int size; int progress; Memory(int asize) { size = asize; buffer = new int[asize]; progress = 0; } } class DownLoad extends Thread { Memory mem; DownLoad(Memory amem) { mem = amem; } public void run() { for (int off = 0;off < mem.size;off += 2) { synchronized(mem) { for (int chunk = 0;chunk < 2;chunk++) { mem.buffer[off+chunk] = off+chunk; mem.progress = off+chunk+1; try { Thread.sleep(200); } catch (InterruptedException e) { ; } } } } } } class Play extends Thread { Memory mem; Play(Memory amem) { mem = amem; } public void run() { for (;;) { synchronized(mem) { for (int off = 0;off < mem.progress;off++) { System.out.print(mem.buffer[off] + " "); } System.out.println(); } if (mem.progress == mem.size) break; try { Thread.sleep(500); } catch (InterruptedException e) { ; } } } } //*/ /* µ¿±âÈ­ ¸Þ¼Òµå public class JavaExam { public static void main(String[] args) { Memory mem = new Memory(16); DownLoad down = new DownLoad(mem); Play play = new Play(mem); down.start(); play.start(); } } class Memory { int[] buffer; int size; int progress; Memory(int asize) { size = asize; buffer = new int[asize]; progress = 0; } synchronized void DownChunk(int off) { for (int chunk = 0;chunk < 2;chunk++) { buffer[off+chunk] = off+chunk; progress = off+chunk+1; try { Thread.sleep(200); } catch (InterruptedException e) { ; } } } synchronized void PlayDowned() { for (int off = 0;off < progress;off++) { System.out.print(buffer[off] + " "); } System.out.println(); } } class DownLoad extends Thread { Memory mem; DownLoad(Memory amem) { mem = amem; } public void run() { for (int off = 0;off < mem.size;off += 2) { mem.DownChunk(off); } } } class Play extends Thread { Memory mem; Play(Memory amem) { mem = amem; } public void run() { for (;;) { mem.PlayDowned(); if (mem.progress == mem.size) break; try { Thread.sleep(500); } catch (InterruptedException e) { ; } } } } //*/ /* ´Ù ¹ÞÀº ÈÄ¿¡ Àç»ýÇϱâ public class JavaExam { public static void main(String[] args) { Memory mem = new Memory(16); DownLoad down = new DownLoad(mem); Play play = new Play(mem); down.start(); play.start(); } } class Memory { int[] buffer; int size; int progress; Memory(int asize) { size = asize; buffer = new int[asize]; progress = 0; } } class DownLoad extends Thread { Memory mem; DownLoad(Memory amem) { mem = amem; } public void run() { for (int off = 0;off < mem.size;off++) { mem.buffer[off] = off; mem.progress = off + 1; try { Thread.sleep(200); } catch (InterruptedException e) { ; } } synchronized(mem) { mem.notify(); } } } class Play extends Thread { Memory mem; Play(Memory amem) { mem = amem; } public void run() { //while (mem.progress != mem.size) {;} try { synchronized(mem) { mem.wait(); } } catch(InterruptedException e) { } for (int off = 0;off < mem.progress;off++) { System.out.print(mem.buffer[off] + " "); } System.out.println(); } } //*/ /* ÀÌÁø ÆÄÀÏ ¾²±â - ¿øÄ¢ÀûÀ¸·Î ¿¹¿Ü ó¸® public class JavaExam { public static void main(String[] args) { FileOutputStream out = null; try { byte[] data = { 8, 9, 0, 6, 2, 9, 9 }; out = new FileOutputStream("test.bin"); out.write(data); System.out.println("Write success"); } catch (IOException e) { System.out.println("File output error"); } finally { try { out.close(); } catch (Exception e) {;} } } } //*/ /* ÀÌÁø ÆÄÀÏ ¾²±â - °£·«È­µÈ Çü½Ä public class JavaExam { public static void main(String[] args) throws Exception { byte[] data = { 8, 9, 0, 6, 2, 9, 9 }; FileOutputStream out = new FileOutputStream("test.bin"); out.write(data); out.close(); System.out.println("Write success"); } } //*/ /* ÀÌÁø ÆÄÀÏ Àбâ public class JavaExam { public static void main(String[] args) throws Exception { FileInputStream in = new FileInputStream("test.bin"); int avail = in.available(); byte[] data = new byte[avail]; in.read(data); in.close(); for (byte b : data) { System.out.print(b); } } } //*/ /* ¹®ÀÚ¿­ ÀÔÃâ·Â - UTF8·Î ÀúÀåµÈ´Ù. public class JavaExam { public static void main(String[] args) throws Exception { String str = "ÀÚ¹Ù Stream ÀÔÃâ·Â"; FileWriter out = new FileWriter("test.txt"); out.write(str); out.close(); System.out.println("Write success"); // ÇÑ ¹®ÀÚ¾¿ Àбâ FileReader in = new FileReader("test.txt"); int ch; for (;;) { ch = in.read(); if (ch == -1) break; System.out.print((char)ch); } in.close(); System.out.println(); // ÇѲ¨¹ø¿¡ Àбâ in = new FileReader("test.txt"); char[] text = new char[100]; int num = in.read(text); System.out.println("ÀÐÀº ¹®ÀÚ °³¼ö = " + num); System.out.println(text); in.close(); } } //*/ /* ANSI ¹®ÀÚ¿­ Àбâ - ¹Ù·Î ÀÐÁö ¸øÇÔ. BOMÀÌ ¾ø´Â UTF8 ¹®¼­¸¸ ÀÐÀ½ public class JavaExam { public static void main(String[] args) throws Exception { //FileReader in = new FileReader("¾Ö±¹°¡.txt"); //FileReader in = new FileReader("¾Ö±¹°¡-Uincode.txt"); //FileReader in = new FileReader("¾Ö±¹°¡-Utf8.txt"); FileReader in = new FileReader("¾Ö±¹°¡-Utf8nb.txt"); char[] text = new char[1000]; int num = in.read(text); System.out.println("ÀÐÀº ¹®ÀÚ °³¼ö = " + num); System.out.println(text); in.close(); } } //*/ /* ¹öÆÛ ÀÌÁø ÀÔÃâ·Â public class JavaExam { public static void main(String[] args) throws Exception { byte[] data = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9 }; BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("test.buf")); //FileOutputStream fout = new FileOutputStream("test.buf"); //BufferedOutputStream out = new BufferedOutputStream(fout); out.write(data); out.close(); System.out.println("Write success"); BufferedInputStream in = new BufferedInputStream(new FileInputStream("test.buf")); byte[] indata = new byte[15]; in.read(indata,0,15); in.close(); for (byte b : indata) { System.out.print(b); } } } //*/ /* ¹öÆÛ ¹®ÀÚ¿­ ÀÔÃâ·Â public class JavaExam { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader("¾Ö±¹°¡-Utf8nb.txt")); char[] text = new char[1000]; int num = in.read(text); System.out.println("ÀÐÀº ¹®ÀÚ °³¼ö = " + num); System.out.println(text); in.close(); } } //*/ /* ÅؽºÆ® ÆÄÀÏÀ» String ŸÀÔÀ¸·Î ¹®ÀÚ¿­·Î Àбâ public class JavaExam { public static void main(String[] args) { String str = ReadFileToString("¾Ö±¹°¡-Utf8nb.txt"); System.out.println(str); } static String ReadFileToString(String Path) { StringBuilder Result = new StringBuilder(); int ch; try { BufferedReader in = new BufferedReader(new FileReader(Path)); for (;;) { ch = in.read(); if (ch == -1) break; Result.append((char)ch); } } catch (Exception e) {;} return Result.toString(); } } //*/ /* º¯¼ö ÀÔÃâ·Â public class JavaExam { public static void main(String[] args) throws Exception { DataOutputStream out = new DataOutputStream(new FileOutputStream("test.dat")); out.writeInt(1234); out.writeDouble(3.14159265); out.writeUTF("String ¹®ÀÚ¿­"); out.close(); System.out.println("Write success"); DataInputStream in = new DataInputStream(new FileInputStream("test.dat")); int i = in.readInt(); double d = in.readDouble(); String str = in.readUTF(); System.out.printf("i = %d, d = %f, str = %s", i, d, str); } } //*/ /* Çະ·Î ÀоîµéÀ̱â public class JavaExam { public static void main(String[] args) throws Exception { LineNumberReader in = new LineNumberReader(new FileReader("¾Ö±¹°¡-Utf8nb.txt")); for (;;) { String Line = in.readLine(); if (Line == null) break; int Num = in.getLineNumber(); System.out.printf("%4d : %s\n", Num, Line); } in.close(); } } //*/ /* ¼­½Ä Ãâ·Â public class JavaExam { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter("format.txt"); int i = 1234; double d = 56.789; String str = "¹®ÀÚ¿­"; out.printf("%6d, %10.2f, %s", i, d, str); out.close(); } } //*/ /* ÆÄÀÏÀÇ Á¤º¸ Á¶»ç public class JavaExam { public static void main(String[] args) { File f = new File("c:\\Temp\\test.txt"); if (f.exists()) { if (f.isFile()) { System.out.println("ÆÄÀÏÀÔ´Ï´Ù."); System.out.println("ÆÄÀÏ°æ·Î : " + f.getParent()); System.out.println("ÆÄÀÏÀ̸§ : " + f.getName()); System.out.println("ÆÄÀÏÅ©±â : " + f.length()); System.out.println("¼û±è ÆÄÀÏ : " + f.isHidden()); System.out.println("Àý´ë °æ·Î : " + f.isAbsolute()); } else if (f.isDirectory()) { System.out.println("µð·ºÅ丮ÀÔ´Ï´Ù."); } } else { System.out.println("ÆÄÀÏÀÌ ¾ø½À´Ï´Ù."); } } } //*/ /* µð·ºÅ丮 ¹× ÆÄÀÏ »ý¼º public class JavaExam { public static void main(String[] args) throws Exception { File folder = new File("c:\\TestFolder"); if (folder.mkdir()) { File file = new File("c:\\TestFolder\\MyFile.txt"); if (file.createNewFile()) { FileWriter out = new FileWriter(file); out.write("Å×½ºÆ® ÆÄÀÏ"); out.close(); } } } } //*/ /* ÆÄÀÏ ¸ñ·Ï Á¶»ç public class JavaExam { public static void main(String[] args) { File f = new File("c:\\"); File[] arFile = f.listFiles(); for (int i = 0; i < arFile.length; i++) { if (arFile[i].isFile()) { System.out.printf("%s %d ¹ÙÀÌÆ®\n",arFile[i].getName(), arFile[i].length()); } else { System.out.printf("[%s] <Æú´õ>\n",arFile[i].getName()); } } } } //*/ /* °´Ã¼ Á÷·ÄÈ­ class Car implements Serializable { String Name; String Color; boolean Gasoline; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void OutInfo() { System.out.printf("À̸§ = %s, »ö»ó = %s, ¿¬·á = %s\n", Name, Color, Gasoline ? "ÈÖ¹ßÀ¯":"°æÀ¯"); } } public class JavaExam { public static void main(String[] args) throws Exception { Car Pride = new Car("ÇÁ¶óÀ̵å", "ÆĶû", true); // ÆÄÀÏ·Î Ãâ·Â ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("pride.car")); out.writeObject(Pride); out.close(); System.out.println("ÆÄÀÏ·Î ±â·Ï"); // ÆÄÀϷκÎÅÍ ÀÔ·Â ObjectInputStream in = new ObjectInputStream(new FileInputStream("pride.car")); Car Pride2 = (Car)in.readObject(); in.close(); Pride2.OutInfo(); } } //*/ /* Á÷·ÄÈ­ ´ë»ó. static, transient´Â Á¦¿ÜµÈ´Ù. class Car implements Serializable { String Name; String Color; transient boolean Gasoline; static int Count = 0; Car(String aName, String aColor, boolean aGasoline) { Name = aName; Color = aColor; Gasoline = aGasoline; } void OutInfo() { System.out.printf("À̸§ = %s, »ö»ó = %s, ¿¬·á = %s\n", Name, Color, Gasoline ? "ÈÖ¹ßÀ¯":"°æÀ¯"); } } public class JavaExam { public static void main(String[] args) throws Exception { Car Pride = new Car("ÇÁ¶óÀ̵å", "ÆĶû", true); // ÆÄÀÏ·Î Ãâ·Â ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("pride2.car")); out.writeObject(Pride); out.close(); System.out.println("ÆÄÀÏ·Î ±â·Ï"); // ÆÄÀϷκÎÅÍ ÀÔ·Â ObjectInputStream in = new ObjectInputStream(new FileInputStream("pride2.car")); Car Pride2 = (Car)in.readObject(); in.close(); Pride2.OutInfo(); } } //*/ /* µðÆúÆ® Á÷·ÄÈ­ class Bitmap implements Serializable { byte[] raster; public Bitmap(int width) { raster = new byte[width]; int i; for (i=0;i<100;i++) raster[i] = 1; for (i=100;i