12-file.key

Similar documents
12-file.key

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

07 자바의 다양한 클래스.key

(Microsoft PowerPoint - java1-lecture9.ppt [\310\243\310\257 \270\360\265\345])

PowerPoint 프레젠테이션

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

rmi_박준용_final.PDF

PowerPoint 프레젠테이션

02 C h a p t e r Java

JAVA PROGRAMMING 실습 09. 예외처리

Java

Cluster management software

Microsoft PowerPoint - 04-UDP Programming.ppt

PowerPoint 프레젠테이션

슬라이드 1

05-class.key

신림프로그래머_클린코드.key

<4D F736F F F696E74202D20C1A63234C0E520C0D4C3E2B7C228B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

09-interface.key

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

PowerPoint Presentation

5장.key

Microsoft PowerPoint - 03-TCP Programming.ppt

untitled

Microsoft PowerPoint - Java7.pptx

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

비긴쿡-자바 00앞부속

자바-11장N'1-502

PowerPoint Presentation

PowerPoint Presentation

歯9장.PDF

PowerPoint 프레젠테이션

歯JavaExceptionHandling.PDF

Semantic Consistency in Information Exchange

PowerPoint 프레젠테이션

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

java.lang 패키지 java.util 패키지 java.io 패키지 콜렉션 2

목차 INDEX JSON? - JSON 개요 - JSONObject - JSONArray 서울시공공데이터 API 살펴보기 - 요청인자살펴보기 - Result Code - 출력값 HttpClient - HttpHelper 클래스작성 - JSONParser 클래스작성 공공

gnu-lee-oop-kor-lec11-1-chap15

<4D F736F F F696E74202D20C1A63235C0E520B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Network Programming

파일로입출력하기II - 파일출력클래스중에는데이터를일정한형태로출력하는기능을가지고있다. - PrintWriter와 PrintStream을사용해서원하는형태로출력할수있다. - PrintStream은구버전으로가능하면 PrintWriter 클래스를사용한다. PrintWriter

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

[ 정보 ] 과학고 R&E 결과보고서 Monte Carlo Method 를이용한 고교배정시뮬레이션 연구기간 : ~ 연구책임자 : 강대욱 ( 전남대전자컴퓨터공학부 ) 지도교사 : 최미경 ( 전남과학고정보 컴퓨터과 ) 참여학생 : 박진명 ( 전

chap01_time_complexity.key

PowerPoint Presentation

chap 5: Trees

Microsoft PowerPoint - java2-lecture2.ppt [호환 모드]

Java ...

PowerPoint 프레젠테이션

자바 프로그래밍

JMF2_심빈구.PDF

Modern Javascript

6장.key

4장.문장

교육자료

ch09

01-OOPConcepts(2).PDF

Chap12

Microsoft PowerPoint - java2-lecture4.ppt [호환 모드]

Microsoft PowerPoint - lec11_1516.ppt [호환 모드]

1

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

JMF3_심빈구.PDF

Microsoft PowerPoint - java2-lecture3.ppt [호환 모드]

13-Java Network Programming

Microsoft Word - java19-1-midterm-answer.doc

PowerPoint Template

JAVA PROGRAMMING 실습 02. 표준 입출력

목차 BUG DEQUEUE 의 WAIT TIME 이 1 초미만인경우, 설정한시간만큼대기하지않는문제가있습니다... 3 BUG [qp-select-pvo] group by 표현식에있는컬럼을참조하는집합연산이존재하지않으면결괏값오류가발생할수있습니다... 4

항상쌍 ( 키, 값 ) 으로만데이터를저장하는클래스 의최고조상 : Map - Map을조상으로하는클래스, HashTable, HashMap, LinkedHashMap, TreeMap 등은데이터를저장할때반드시 키 와 값 의쌍으로저장한다. - Map에저장되는 키 는중복되면안되

11강-힙정렬.ppt

슬라이드 1

03-JAVA Syntax(2).PDF

슬라이드 1

Secure Programming Lecture1 : Introduction

14-Servlet

중간고사

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

슬라이드 1

Javascript.pages

자바GUI실전프로그래밍2_장대원.PDF

PowerPoint Presentation

11장.key

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

MasoJava4_Dongbin.PDF

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

Design Issues

슬라이드 1

PowerPoint Presentation

6장정렬알고리즘.key

Week5

Java XPath API (한글)

Transcription:

11 2

,, (Generic) (Collection) : : : :?

(String).. java.lang.stringbuffer. s String s = "abcd"; s = s + "e"; a b c d e a b c d e

,., "910359,, " "910359" " " " " (token) (token),, (delimiter).

java.util.stringtokenizer String s = "910359,, "; StringTokenizer t = new StringTokenizer(s, ","); t.nexttoken(); // "910359" t.nexttoken(); // " " t.nexttoken(); // " " t.nexttoken(); // NoSuchElementException

String s = "$13.46"; StringTokenizer t = new StringTokenizer(s, "$."); t.nexttoken(); // "13" t.nexttoken(); // "46" t.nexttoken(); // NoSuchElementException

class StringTokenizer new StringTokenizer (String text, String delim) text delim nexttoken(): String nexttoken(string new_delimiters): String hasmoretokens(): boolean, 0 nexttoken() counttokens(): int

(Files) (file): (character file): (binary file): 0 1 (open) (close).. (input) : (output) :

FileWriter.. PrintWriter ofile = new PrintWriter (new FileWriter("file.txt")); PrintWriter FileWriter PrintWriter FileWriter print, println print println file

, import java.io.*; IO IOException. public class Output1 { public static void main(string[] args) throws IOException { PrintWriter outfile = new PrintWriter(new FileWriter("test.txt")); outfile.println("hello to you!"); outfile.print("how are"); outfile.println(" you?"); outfile.println(47+2); outfile.close();

FileReader BufferedReader ifile = new BufferedReader (new FileReader("file.txt"));.. BufferedReader BufferedRe ader FileReader FileReader readline readline file

, import java.io.*; import javax.swing.*; public class CopyFile { public static void main(string[] args) throws IOException { String f = JOptionPane.showInputDialog("Input filename, please: "); BufferedReader infile = new BufferedReader(new FileReader(f)); PrintWriter outfile = new PrintWriter(new FileWriter(f + ".out")); while (infile.ready()) { outfile.println(infile.readline()); infile.close(); outfile.close();

GUI

, import java.io.*; import javax.swing.*; public class CopyFile { public static void main(string[] args) throws IOException { JFileChooser chooser = new JFileChooser(); chooser.setdialogtitle("."); int result = chooser.showdialog(null, "Copy"); if(result!= JFileChooser.APPROVE_OPTION) System.exit(0); String f = chooser.getselectedfile().tostring(); BufferedReader infile = new BufferedReader(new FileReader(f)); PrintWriter outfile = new PrintWriter(new FileWriter(f + ".out")); while (infile.ready()) { outfile.println(infile.readline()); infile.close(); outfile.close();

: System.out: System.out.println System.in: System.in InputStream. System.in BufferedReader BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); String s = keyboard.readline();

, 31 20250 42 24500 18 18000! 627750 1029000 324000! PayrollReader.,, PayrollWriter.,.

class PayrollReader Methods getnextrecord(): boolean.. nameof(): String. hoursof(): int. payrateof(): double close()..

import java.io.*; import java.util.*; public class PayrollReader { private BufferedReader infile; private String EOF = "!"; private String name; private int hours, payrate; public PayrollReader(String file_name) { infile = new BufferedReader(new FileReader(file_name)); public String nameof() { return name; public int hoursof() { return hours; public int payrateof() { return payrate; public void close() { infile.close();

public boolean getnextrecord() { if(!infile.ready()) return false; String line = infile.readline(); StringTokenizer t = new StringTokenizer(line, " "); String s = t.nexttoken().trim(); if(s.equals(eof) t.counttokens()!= 2) return false; name = s; hours = new Integer(t.nextToken().trim()).intValue(); payrate = new Integer(t.nextToken().trim()).intValue(); return true;

import javax.swing.*; public class Payroll { private static void processpayroll(string in, String out) { PayrollReader reader = new PayrollReader(in); PayrollWriter writer = new PayrollWriter(out); while(reader.getnextrecord()) { int pay = reader.hoursof() * reader.payrateof(); writer.printcheck(reader.nameof(), pay); reader.close(); writer.close(); public static void main(string[] args) { String in_name = JOptionPane.showInputDialog("Plead type input payroll name: "); String out_name = JOptionPane.showInputDialog("Plead type output payroll name: "); if(in_name!= null && out_name!= null) processpayroll(in_name, out_name);

getnextrecord??.?. false (log)!

? infile.readline() IOException. false. t.counttoken()!= 2

try, catch. catch try { ;... catch ( ) { ;...

public boolean getnextrecord() { if(!infile.ready()) return false; String line = infile.readline(); StringTokenizer t = new StringTokenizer(line, " "); String s = t.nexttoken().trim(); if(s.equals(eof) t.counttokens()!= 2) return false; name = s; hours = new Integer(t.nextToken().trim()).intValue(); payrate = new Integer(t.nextToken().trim()).intValue(); return true;

public boolean getnextrecord() { boolean result = false; try { if(infile.ready()) return false; String line = infile.readline();... if(!s.equals(eof) && t.counttokens() == 2) {... result = true; catch (IOException e) { System.out.println("PayrollReader error: " + e.getmessage()); return result;

public boolean getnextrecord() { boolean result = false; try { if(infile.ready()) return false; String line = infile.readline();... if(!s.equals(eof)) { if(t.counttokens() == 2) {... result = true; else { System.out.println("PayrollReader: bad record format: " + line + " Skipping record"); result = getnextrecord(); catch (IOException e) { System.out.println("PayrollReader error: " + e.getmessage()); return result;

public boolean getnextrecord() { boolean result = false; try {... if(!s.equals(eof)) { if(t.counttokens() == 2) {... result = true; else throw new RuntimeException(line); catch (IOException e) { System.out.println("PayrollReader error: " + e.getmessage()); catch (RuntimeException e) { System.out.println("PayrollReader error: bad record format: " + e.getmessage() + " Skipping record"); result = getnextrecord(); return result;

., Exception in thread "main" java.io.filenotfoundexception: /Volumes/Pamela/ Users/oukseh/11.csv (Permission denied) at java.io.fileinputstream.open(native Method) at java.io.fileinputstream.<init>(fileinputstream.java:120) at java.io.fileinputstream.<init>(fileinputstream.java:79) at java.io.filereader.<init>(filereader.java:41) at CopyFile.main(CopyFile.java:11)

getmessage(): String tostring(): String. printstacktrace (),

Object Throwable Exception InterruptedException RuntimeException IOException ArithmeticException ArrayIndexOutOfBounds Exception ClassCastException NullPointerException FileNotFoundExcepti EOFException InterruptedIOExceptio

catch catch(< > e) {... < >. Exception RuntimeException IOException

, private int readanintfrom(bufferedreader view) throws IOException { int num; try { System.out.print("Type an int: "); String s = view.readline(); num = new Integer(s).intValue(); catch (Exception e) { System.out.println("Error: " + e.getmessage() + " not an integer; try again."); num = readanintfrom(view); // restart return num; Exception RuntimeException RuntimeException NumberFormatException

throws.. Java RuntimeException..

public class ExceptionExample { public ExceptionExample() { public void f() { try { g(); catch (RuntimeException e) { System.out.println("caught at f"); System.out.println("f completes"); public void g() { try { PrintWriter outfile = new PrintWriter(new FileWriter("text.out")); try { outfile.println( h() ); catch (NullPointerException e) { System.out.println("null pointer caught at g"); catch (IOException e) { System.out.println("io error caught at g"); System.out.println("g completes"); private int h() { int[] r = new int[2]; return r[3]; // ArrayIndexOutOfBoundsException! f?

A, B. try {... catch (?) {... 1: throw new RuntimeException("A"); throw new RuntimeException("B"); try {... catch (RuntimeException e) { String m = e.getmessage(); if(m.equals("a"))... if(m.equals("b"))...

2: class MyExceptionA extends Exception { class MyExceptionB extends Exception { throw new MyExceptionA(); throw new MyExceptionB(); try {... catch (MyExceptionA e) {... catch (MyExceptionB e) {...

(Collection)

(Collection) (element),,,

(Collection)

Collection<E> Map<K, V> Set<E> List<E> Queue<E> 인터페이스 클래스 HashSet<E> ArrayList<E> Vector<E> LinkedList<E> HashMap<K, V> Stack<E>

(Generic) : Vector <E> E Vector <Integer>, Vector<String> int, double. Wrapper (Integer, Double)

<E>,,,,

import java.util.vector; public class VectorEx { public static void main(string[] args) { int sum = 0; // Vector<Integer> v = new Vector<Integer>(); v.add(5); v.add(4); v.add(-1);// 5, 4, -1 v.add(2, 100); // 4-1 100 System.out.println(" : " + v.size()); System.out.println(" : " + v.capacity()); // for(int i=0; i<v.size(); i++) { int n = v.get(i); // i System.out.println(n); // int sum = 0; for(int i=0; i<v.size(); i++) { int n = v.elementat(i); // i sum += n; System.out.println(" : " + sum);

import java.util.vector; class Point { private int x, y; public Point(int x,int y) {this.x = x; this.y = y; public String tostring() { return "(" + x + "," + y + ")"; public class PointerVectorEx { public static void main(string[] args) { Vector<Point> v = new Vector<Point>(); // 3 Point v.add(new Point(2, 3)); v.add(new Point(-5, 20)); v.add(new Point(30, -8)); v.remove(1); // 1 Point(-5, 20) // Point for(int i=0; i<v.size(); i++) { Point p = v.get(i); // i Point System.out.println(p); // p.tostring() p

HashMap <K, V> (key) (value) K: V: put(), get() :

import java.util.*; public class HashMapDicEx { public static void main(string[] args) { // HashMap HashMap<String, String> dic = new HashMap<String, String>(); // 3 (key, value) dic dic.put("baby", " "); // "baby" key, " " value dic.put("love", " "); dic.put("apple", " "); // dic (key, value) // Set Set<String> keys = dic.keyset(); // Set Iterator. Iterator<String> it = keys.iterator(); while(it.hasnext()) { String key = it.next(); // String value = dic.get(key); // System.out.print("(" + key + "," + value + ")"); System.out.println();

// Scanner scanner = new Scanner(System.in); for(int i=0; i<3; i++) { System.out.print("?"); String eng = scanner.next(); // ' ' eng ' ' kor String kor = dic.get(eng); if(kor == null) System.out.println(eng + "."); else System.out.println(kor);

(Sequential Search). public static int search(string key, String[] a) { for (int i = 0; i < a.length; i++) if ( a[i].equals(key) == 0 ) return i; return -1;

? 1 1 1000.? 1 2

? 1 1 1000.?! 1 2 1000 500. (10 7 x 10 3 / (2 x 10 7 ) = 500), 500.

(Binary Search),,

public class BinarySearch { public static int search(string key, String[] a) { return search(key, a, 0, a.length); // : a[lo] <= key <= a[hi-1]. public static int search(string key, String[] a, int lo, int hi) { if (hi <= lo) return -1; int mid = lo + (hi - lo) / 2; int cmp = a[mid].compareto(key); if a.compareto(b): a b -1, 0, -1 (cmp > 0) return search(key, a, lo, mid); else if (cmp < 0) return search(key, a, mid+1, hi); else return mid; public static void main(string[] args) { String[] arr = new String[4]; arr[0] = a"; arr[1] = b"; arr[2] = c"; arr[3] = "d"; System.out.println(search("c", arr));

? N : 1 N / 2 N N/2 N/4 1, 1 2 : log2n 1 2! 1 4! 2! 1 8! 4! 2! 1 16! 8! 4! 2! 1 32! 16! 8! 4! 2! 1 64! 32! 16! 8! 4! 2! 1 128! 64! 32! 16! 8! 4! 2! 1 256! 128! 64! 32! 16! 8! 4! 2! 1 512! 256! 128! 64! 32! 16! 8! 4! 2! 1 1024! 512! 256! 128! 64! 32! 16! 8! 4! 2! 1

? 1 1 1000.?! 1 2 1000 0.001. (log2(10 7 ) x 10 3 ) / (2 x 10 7 ) = 0.001)

(Sorting) N :,,,,,...,,,,...

(Insertion Sort)

: https://gmlwjd9405.github.io/2018/05/06/algorithm-insertion-sort.html

public class Insertion { public static void sort(string[] a) { int N = a.length; for (int i = 1; i < N; i++) for (int j = i; j > 0; j--) if (a[j-1].compareto(a[j]) > 0) exch(a, j-1, j); else break; private static void exch(string[] a, int i, int j) { String swap = a[i]; a[i] = a[j]; a[j] = swap; public static void main(string[] args) { String[] arr = new String[4]; arr[0] = d"; arr[1] = "a"; arr[2] = c"; arr[3] = "b"; sort(arr); for (int i = 0; i<arr.length; i++) System.out.println(arr[i]);

? ( : N) : N-1 : i (n-1) + (n-2) +... + 2 + 1 = n(n-1)/2

(Complexity) (order of growth) : :. : (asymptotic complexity) Θ(f(n)) (n: ). f(n) : k 1 f(n) apple apple k 2 f(n) n 2, 1000 x n 2, 3 x n 2 + 1000 x n Θ(n 2 ), k1, k2 n

(Complexity) Θ(n 2 )

(Complexity) Θ(n) Θ(n 2 ) Θ(1) Θ(n) Θ(1) Θ(log 2 n)

10 7 1 3 10 12 1 2 : http://www.cs.princeton.edu/courses/archive/fall09/cos126/

(Merge Sort)

: https://gmlwjd9405.github.io/2018/05/06/algorithm-merge-sort.html

public class Merge { public static void sort(string[] a) {sort(a, 0, a.length); // Sort a[lo, hi). public static void sort(string[] a, int lo, int hi) { int N = hi - lo; if (N <= 1) return; // Recursively sort left and right halves. int mid = lo + N/2; sort(a, lo, mid); sort(a, mid, hi); // Merge sorted halves String[] aux = new String[N]; // Merge into auxiliary array. int i = lo, j = mid; for (int k = 0; k < N; k++) { if (i == mid) aux[k] = a[j++]; else if (j == hi) aux[k] = a[i++]; else if (a[j].compareto(a[i]) < 0) aux[k] = a[j++]; else aux[k] = a[i++]; // Copy back. for (int k = 0; k < N; k++) a[lo + k] = aux[k];

, Θ(nlog 2 n)

(10 ) 10 7 3 3 10 12 2 : http://www.cs.princeton.edu/courses/archive/fall09/cos126/

,, (Generic) (Collection) : : : :?