초급과정/java

import java.util.ArrayList; import java.util.Collection; import java.util.List; public class HistoGram { /* * 요구사항. * * 주사위 2개를 던져서 총 주사위 합을 * * 1000번 시행 후 해당 값을 저장 할 것 (리스트 ) * 전체 히스토그램을 구해 볼 것 * 주사위 눈은 1~6으로 구현되어 있음. * */ List diceList = new ArrayList(); public static void main(String[] args) { HistoGram hg = new HistoGram(); for(int i=0; i
1 import java.util.HashMap; import java.util.Iterator; /** *HashMap *key 와 value 로 이루어짐 *key 값은 중복을 허용하지 않고 순서가 보장되지 않음. * *Map 타입의 컬렉션 * *주요 메소드 *.put(key, value); : 데이터 입력 key 값은 중복되지 않음. value는 중복 될 수 있음. *.get(key) : 입력 받은 value 값을 key 값을 통해 꺼내 올 수 있음. *.keySet() : key 로 이루어진 hashSet 값을 가져옴. * * */ public class MapExample { public static void main(String[] args) { /* * 제네릭 정보 * HashMap * */ ..
class Solution { public String solution(String my_string) { String answer = ""; //문자열 하나씩 쪼개기 char[] ch = my_string.toCharArray(); //뒤에 문자열 부터 꺼내기 for(int i =0; i
public class StaticMain { public static void main(String[] args) { int a = StaticTest.a; StaticTest.method2(); //Static을 선언하지 않은 것은 이렇게 불러와야 함 위 코드보다 불편. //Static을 남발하면 안되는 이유: 누군가가 건드렸을때 값이 변하기때문에 고정된 값 쓰기 힘듦 StaticTest st = new StaticTest(); int b = st.b; st.method1(); } } public class StaticTest { static int a = 10; int b = 10; public static void main(String[] args) { StaticTest s1 =new Stati..
* 디자인 패턴 중에 하나인 싱글톤 * 클래스를 여러개 만들지 못하도록 방지함. public class SingleTon { private static SingleTon singleTon = null; int a =10; //singleTon이 호출될때 메모리가 사용됨 private SingleTon() { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } }; public static SingleTon getInstance() { System.out.println("객체가 호출 되었습니다."); if (singleTon == null) { singleTon = new SingleTon(); } Syste..
import java.util.Scanner; public class HomeWork2 { static Scanner sc=new Scanner(System.in); public static void main(String[] args) { question1(); question2(); } public static void question1() { // 정수 하나를 설정하고 키보드로 임의의 수를 입력 받아 // 입력받은 수가 크면 "더 작은 수를 입력하세요"를 출력하고 // 다시 수를 입력 받는다. 입력 받은 수가 더 작으면 // "더 큰 수를 입력하세요"를 출력하고 다시 수를 입력 받는다. // 설정된 값과 같은 값을 몇번만에 맞추는지를 출력하는 // 프로그램을 작성하시오. int question = 1..
import java.util.Arrays; public class SortMethod { public static void main(String[] args) { SortMethod sort = new SortMethod(); // 버블정렬 만들어놓은 메소드로 불러오기 int[] num = { 67, 55, 9, 86, 98 }; System.out.println(Arrays.toString(num)); int[] result = sort.sort(num); System.out.println(Arrays.toString(result)); System.out.println("----------------------"); int[] num2 = { 10, 55, 37, 20, 98 }; System.out..
public class Calculator {//HomeWork6 public static void main(String[] args) { Calculator c = new Calculator(); double add = c.add(5, 10); System.out.println("x + y = "+add); double minus = c.minus(8, 10); System.out.println("x - y = "+minus); double division = c.division(9, 4); System.out.println("x / y = "+division); double multi = c.multi(7, 6); System.out.println("x * y = "+multi); //System.o..
import java.util.Arrays; public class LottoMethod { public static void main(String[] args) { LottoMethod lm = new LottoMethod(); //System.out.println(lm.generateLotto()); //int[] lotto = lm.generateLotto(); //System.out.println(Arrays.toString(lotto)); //int[][] paper = lm.lottoPaper(); //for(int i=0; i페이퍼->로또한줄 순으로 //20000원으로 로또 몇장을 살 수 있는지 구현. int[][][] bundle = lm.lottoBundle(6000); for(int i..
whalerice
'초급과정/java' 카테고리의 글 목록