Java(281)
-
Java HashSet
프로젝트 내 src 내 javabasic 패키지 내 Ex8Set.java package javabasic; import java.util.HashSet; public class Ex8Set { public static void main(String[] args) { // TODO Auto-generated method stub String[] str = { "Java", "Beans", "Java", "XML", "XML" }; HashSet hs1 = new HashSet(); HashSet hs2 = new HashSet(); for (String n : str) { // hs1에 중복된값이 있어서 추가가 안되는 경우에는 // hs2에 추가를 하시오 라는 뜻 if (!hs1.add(n)) hs2.ad..
2023.01.30 -
Java Set
프로젝트 내 src 내 javabasic 패키지 내 Ex7Set.java package javabasic; import java.util.HashSet; import java.util.Set; public class Ex7Set { public static void main(String[] args) { // TODO Auto-generated method stub //Set set1=new HashSet(); //Set 의 특징 //1. 순서없이 들어간다(비순차적) //2. 중복된 데이타는 한번만 들어간다 Set set1=new HashSet();//생성부분의 제네릭 타입은 생략가능 //중복된 데이타가 없어서 들어갈경우 true반환 //중복된 데이타가 잇어서 안들어갈경우 false반환 System.ou..
2023.01.30 -
Java 사용자 정의 예외 처리
프로젝트 내 src 내 javabasic 패키지 내 Ex6UserException.java package javabasic; import java.util.Scanner; //사용자 이셉션 //throw 를 이용해서 강제로 이셉션을 발생시킨다. class UserException extends Exception { public UserException(String msg) { // TODO Auto-generated constructor stub super(msg); } } //이름과 나이를 입력받는데 //이름에 "김태희" 를 입력하면 이셉션 발생 //나이는 50세가 넘으면 이셉션 발생 public class Ex6UserException { public static void dataInput() thr..
2023.01.29 -
Java InterruptedException
프로젝트 내 src 내 javabasic 패키지 내 Ex5Exception.java package javabasic; public class Ex5Exception { public static void main(String[] args) { // TODO Auto-generated method stub Thread targetThread = new targetThread(); targetThread.start(); System.out.println("안녕하세요..3초후에 봐요"); try { Thread.sleep(3000); //Thread.sleep(10000); //3초 뒤 targetThread interrupt 한다. targetThread.interrupt(); } catch (Interrup..
2023.01.29 -
Java IOException
프로젝트 내 src 내 javabasic 패키지 내 Ex4Exception.java package javabasic; import java.io.FileWriter; import java.io.IOException; public class Ex4Exception { public static void main(String[] args) { // TODO Auto-generated method stub // 파일에 저장 FileWriter fw = null; String fileName = "C:\\java0901\\memo.txt"; try { fw = new FileWriter(fileName); fw.write("파일에 저장했어요"); System.out.println("파일확인"); } catch (..
2023.01.29 -
Java catch
프로젝트 내 src 내 javabasic 패키지 내 Ex3Exception.java package javabasic; import java.util.Scanner; public class Ex3Exception { public static void process() throws NumberFormatException, ArithmeticException { Scanner sc = new Scanner(System.in); int su1, su2; System.out.println("두개의 숫자를 입력하세요"); su1 = Integer.parseInt(sc.nextLine()); su2 = Integer.parseInt(sc.nextLine()); int div = su1 / su2; System.out..
2023.01.29