11 장 . 패키지와 주요 클래스

  • Published on
    19-Mar-2016

  • View
    84

  • Download
    5

Embed Size (px)

DESCRIPTION

11 . . Java. public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt (a1[0]); b = Integer.parseInt (a1[1]); sum = a + b ; // System.out.println (" " + sum + " "); - PowerPoint PPT Presentation

Transcript

<p>PowerPoint Presentation</p> <p>11. 1public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // System.out.println(" " + sum + ""); }}Java12 2section 1 </p> <p>section 2 java.lang </p> <p>section 3 Object </p> <p>section 4 (Wrapper) 4-1 Integer 4-2 Character 4-3 Byte 4-4 Short 4-5 Long 3 3section 5 </p> <p>section 6 String 6-1 6-2 6-3 6-4 6-5 </p> <p>section 7 StringBuffer </p> <p>section 8 </p> <p>section 9 Random </p> <p>section 10 Arrays 4 4 1 5 11. 5 1 6JDK java.lang,.java.lang.Object.java.util.java.io.java.nettelnet,ftp,http.java.awt(GUI).java.awt.eventAWT.java.applet11. 6 1 7 import import java.util.Date; ...... Date date = new Date(); ......java.util.Dateimport java.util.*; ....... Date date = new Date(); Random random = new Random(); Stack stack = new Stack(); Hashtable hashtable = new Hashtable(); ........... ............java.utiljava.util11. 7 2 java.lang 8java.lang import 11. 8 2 java.lang 9java.lang</p> <p>345 page11. 9 3 Object 10java.lang.Object 11. 10 3 Object 11java.lang.ObjectOjbectclone()booleanequals(Objectobject) true, falsevoidfinalize()(garbagecollection).finalize()ClassgetClass()ClassinthashCode()hash.StringtoString().voidnotify().voidnotifyAll().voidwait().11. 11 4 (Wrapper) 12 </p> <p>(wrapper) , class ValueandWrapper { public static void main(String args[]) { int num1 = 20; Integer num2 = new Integer(30) int total = num1 + num2.intValue(); System.out.println(" : " + total); }}IntegIntegIntegernum2=30;IntegerintValue()11. 124-1 Integer 4 (Wrapper) 13Integer nteger(intn)nteger(Stringstr)11. 134-1 Integer 4 (Wrapper) 14IntegerbytebyteValue()bytedoubledoubleValue()doublefloatfloatValue()floatintintValue()intlonglongValue()longshortshortValue()shortStringtoString()booleanequals(ObjectIntegerObj)IntegerObjtrue,falsestatic Integerdecode(String str) throwsNumberFormatExceptionstrIntegerstatic int parseInt(String str) throwsNumberFormatExceptionstrint11. 144-1 Integer 4 (Wrapper) 15Integerstatic int parseInt(String str, int radix) throws NumberFormatException str int radixstaticStringtoBinaryString(intnum)num2StringstaticStringtoHexString(intnum)num16StringstaticStringtoOctalString(intnum)num8Stringstatic Integer valueOf(String str) throwsNumberFormatExceptionstrIntegerstaticIntegervalueOf(Stringstr,intradix)throwsNumberFormatExceptionstrIntegerradix11. 154-1 Integer 4 (Wrapper) 16IntegerTest1.java01020304050607080910111213141516public class IntegerTest1 { public static void main(String args[]) { Integer num1 = new Integer(13); Integer num2 = 25; int hap = num1.intValue() + num2.intValue(); System.out.println("num1 : " + num1.intValue()); System.out.println("num2 : " + num2.intValue()); System.out.println(" = " + hap); System.out.println(" 2 : " + Integer.toBinaryString(hap)); System.out.println(" 8 : " + Integer.toOctalString(hap)); System.out.println(" 16 : " + Integer.toHexString(hap)); Integer11. 164-1 Integer 4 (Wrapper) 17IntegerTest1.java171819202122 System.out.println("if(num1 == num2) : " + num1.equals(num2)); Integer num3 = new Integer("444"); System.out.println(" '444' : " + num3.intValue()); }}11. 174-1 Integer 4 (Wrapper) 18 00 :new,.00 :intValue().00~00 :.2,8,16.00 :Integer.IntegerInteger.11. 184-1 Integer 4 (Wrapper) 19</p> <p>11. 194-2 Character 4 (Wrapper) 20Character char Character(char c)11. 204-2 Character 4 (Wrapper) 21CharacterstaticbooleanisDefined(charch)chUnicodetruefalsestaticbooleanisDigit(charch)chtruefalsestaticbooleanisLetter(charch)chtruefalsestaticbooleanisLetterOrDigit(charch)chtruefalsestaticbooleanisLowerCase(charch)chtruefalsestaticbooleanisSpace(charch)chtruefalsestaticbooleanisUpperCase(charch)chtruefalsestaticchartoLowerCase(charch)chstaticchartoUpperCase(charch)ch11. 214-2 Character 4 (Wrapper) 22CharacterTest1.java01020304050607080910111213141516class CharacterTest1 { public static void main(String args[]) { char a[] = {'a', ' ', '?', 'C', '5', 'A'}; for(int i=0; i 0) { String t = array1[i]; array1[i] = array1[j]; array1[j] = t; 11. 606-3 6 String 61CompareTest.java181920212223 } } System.out.print(array1[i] + " "); } }}11. 616-3 6 String 62 02 :.mail()..08, 09 :.09~10 :.14 :0..1,.,..11. 626-3 6 String 63</p> <p>11. 636-4 6 String 64 indexOf() : lastindexOf() : intindexOf(Stringstr)intindexOf(intch,intstartIndex)intindexOf(Stringstr,intstartIndex)intlastindexOf(Stringstr)intlastindexOf(intch,intstartIndex)intlastindexOf(Stringstr,intstartIndex)11. 646-4 6 String 65StringIndexTest.java010203040506070809101112public class StringIndexTest { public static void main(String args[]) { String s = "1234567890JAVA1234567890java"; System.out.println(s); System.out.println (" : " + s.length()); System.out.println ("indexOf(J) = " + s.indexOf('J')); System.out.println ("lastIndexOf(9) = " + s.lastIndexOf('9')); System.out.println ("indexOf(5, 5) = " + s.indexOf('5', 5));J95511. 656-4 6 String 66StringIndexTest.java1314151617181920 System.out.println ("lastIndexOf(5, 18) = " + s.lastIndexOf('5', 17)); System.out.println ("indexOf(java, 10) = " + s.indexOf("java", 10)); System.out.println ("lastIndexOf(Java, 40) = " + s.lastIndexOf("Java", 23)); }}17510java23Java11. 666-4 6 String 67 07~10 :..11~14 :.15~18 :.</p> <p>11. 676-5 6 String 68 </p> <p> Stringsubstring(intstartIndex,intendIndex)Stringconcat(Stringconstr)Stringreplace(charoriginal,charreplacement)Stringtrim()staticStringvalueOf(doublenum)staticStringvalueOf(longnum)staticStringvalueOf(Objectobj)staticStringvalueOf(charchars[])staticStringvalueOf(charchars[],intstartIndex,intnumChars)11. 686-5 6 String 69 StringtoLowerCase()StringtoUpperCase()11. 696-5 6 String 70SubStringTest.java01020304050607080910111213public class SubStringTest { public static void main(String args[]) { String str = " "; System.out.println(" 5 8 : " + str.substring(5,8)); System.out.println(str.concat(" ")); System.out.println(str.replace('','')); str = " " + str + " "; System.out.println(" str : " + str.length()); str = str.trim(); System.out.println(" str : " + str.length()); }}5811. 706-5 6 String 71 04, 05 :.06 :.07 :.10 :.</p> <p>11. 716-5 6 String 72ConvertStringTest.java01020304050607080910111213public class ConvertStringTest { public static void main(String args[]) { int a = 2002 ; char b[] = {'W','o','r','l','d','c','u','p'}; System.out.println(String.valueOf(a) + " " + String.valueOf(b) + " in Korea"); String s1 = String.valueOf(b); System.out.println(String.valueOf(a) + " " + s1.toUpperCase() + " in Korea"); System.out.println(String.valueOf(a) + " " + String.valueOf(b).toUpperCase() + " in Korea"); }}2002 11. 726-5 6 String 73 00, 00 :..,.String.valueOf(b).StringString.07~09. . String.valueOf(b).toUpperCase().concat("java").replace('j','p')</p> <p>11. 73 7 StringBuffer 74StringBuffer StringBuffer() : 16 StringBuffer(int size) : size StringBuffer(String str) : str 16 StringBuffer()StringBuffer(intsize)StringBuffer(Stringstr)11. 74 7 StringBuffer 75StringBufferStringBufferappend(booleanb)bStringBufferappend(charch)chStringBufferappend(doubled)dStringBufferappend(floatf)fStringBufferappend(inti)iStringBufferappend(longl)lStringBufferappend(Objectobj)objStringBufferappend(Objectobj)objStringBufferappend(Stringstr)strintcapacity()charcharAt(inti)StringBufferdelete(intstart,intend)startend11. 75 7 StringBuffer 76StringBufferStringBufferinsert(inti,booleanb)ibStringBufferinsert(inti,charch)ichStringBufferinsert(inti,intj)ijStringBufferinsert(inti,longl)ilStringBufferinsert(inti,Objectobj)iobjStringBufferinsert(inti,Stringstr)istrintlength()StringBufferreverse()voidsetCharAt(inti,charch)ichvoidsetLength(intlen)lenStringtoString()StringStringsubstring(ints,inte)sestring11. 76 7 StringBuffer 77StringBufferTest1.java010203040506070809101112public class StringBufferTest1 { public static void main(String args[]) { StringBuffer str1 = new StringBuffer("Hello JAVA"); StringBuffer str2 = new StringBuffer(" "); System.out.println(" =&gt; " + str1); System.out.println(" =&gt; " + str1.length()); System.out.println(" =&gt; " + str1.capacity()); System.out.println(" =&gt; " + str2); System.out.println(" =&gt; " + str2.length()); System.out.println(" =&gt; " + str2.capacity()); }}11. 77 7 StringBuffer 78 00 :StringBuffer16.</p> <p>11. 78 7 StringBuffer 79StringBufferTest2.java01020304050607080910111213141516public class StringBufferTest2 { public static void main(String args[]) { StringBuffer str1 = new StringBuffer(" "); System.out.println(" =&gt; " + str1); System.out.println(" =&gt; " + str1.insert(3,"Power ")); System.out.println(" 5 =&gt; " + str1.charAt(4)); str1.setCharAt(0, ''); System.out.println("0 '' =&gt; " + str1); str1.setLength(8); System.out.println(" =&gt; " + str1); System.out.println(" =&gt; " + str1.reverse()); }}340811. 79 7 StringBuffer 80 00 :..</p> <p>11. 80 8 81java.util</p> <p>384 page11. 81 8 82java.util</p> <p>384 page11. 82 9 Random 83Random double, float, int, long </p> <p>Random Random() : Random (long seed) : seed Random()Random(longseed)11. 83 9 Random 84RandomvoidnextBytes(bytebuffer[])buffer.floatnextFloat()floatintnextInt()intlonggetLong()longdoublenextDouble()doubledoublenextGaussian()GaussiandoublevoidsetSeed(longnewseed)seednewseed11. 84 9 Random 85RandomTest.java010203040506070809101112import java.util.*;public class RandomTest { public static void main(String args[]) { Random rangen = new Random(); for(int i = 1 ; i </p>

Recommended

View more >