Collection을 활용해서 정렬을 할 수 있습니다. List product = new ArrayList(); 이런 List가 있는데 이 안에는 code 와 sell_price가 들어있었습니다. sell_price로 정렬을 하는 방법을 찾아봤습니다. Collections.sort(product, new Comparator() { @Override public int compare(Product o1, Product o2) { if(o1.getSellPrice() o2.getSellPrice()){ return 1; } return 0; } }); 이렇게 하면 두 값을 비교해서 정렬을 해줍니다.
width와 height를 입력하면 area와 perimeter를 우선 구하는 방법을 썻다. package FirstPackage; import java.util.Scanner; public class Rectangle { static float hh; static float ww; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("width:"); float wid = scanner.nextFloat(); ww = wid; System.out.println("height:"); float hei = scanner.nextFloat(); hh = hei; getArea()..
객체는 다른 것과 구별을 할 수 있으며 속성과 동작으로 구성되어 있다. 사람의 이름과 나이는 필드에 입력되며 달린다 뛴다 등의 동작은 메소드에 입력된다. 메소드 호출은 객체가 다른 객체의 기능을 이용하는 것이다. 메소드 호출은 '객체.메소드(...)' 이렇게 .으로 연결하여 접근한다. 객체는 개별적으로 사용할 수 있지만 대부분은 다른 객체와 연결이 되어 있다. 집합관계는 눈에 보이지 않는 부품을 담당하는 객체들과 눈에 보이는 완성품을 담당하는 객체의 관계이다. 사용관계는 객체 간 상호작용을 말한다. 서로 사용하는 관계이다. 상속관계는 상위 객체를 기반으로 하위 객체를 생성하는 것이다. 네이버가 부모고 네이버 블로그가 자식인 것 처럼? 캡슐화란 객체의 필드와 메소드를 하나로 묶은 다음에 ..
package Chapter05; import java.util.Scanner; public class exercise09 { public static void main(String[] args) { boolean run = true; int studentNum = 0; int[] scores = null; Scanner scanner = new Scanner(System.in); while(run) { System.out.println("-----------------------------------"); System.out.println("1.학생수| 2.점수입력| 3.점수리스트| 4.분석| 5. cancel"); System.out.println("----------------------------..
문제: 10진수 2진수 8진수의 대칭수가 되는 수 중 10이상 최솟값을 구하여라 StringBuffer로 10진수, 2진수, 8진수의 reverse를 구해서 equals로 비교를 하였다 package AlQuiz; public class Quiz01 { public static void main(String[] args) { int num = 11; while (true) { //2진수 StringBuffer sBuf = new StringBuffer(); String numBinary = Integer.toBinaryString(num); StringBuffer bBack = sBuf.append(numBinary).reverse(); String nbnb = bBack.toString(); /..
Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); int f = Integer.parseInt(input.split(" ")[0]); int v = Integer.parseInt(input.split(" ")[1]); int result = 0; int a = 0; int b = 0; if(f > v){ a = f; b = v; } else { a = v; b = f; } boolean run = true; while(run) { if(b == 0) { result = a; run = false; } else if (a == 0){ result = b; run = false; }else { int c = a % b; ..
import java.util.Scanner; import java.util.regex.Pattern; public class HexMain { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String number = scanner.nextLine(); String[] nn = number.split(""); boolean flag = Pattern.matches("^[a-fA-F0-9]*$", number); try { if(flag) { System.out.println(Integer.parseInt(number, 16)); } else { throw new HexException(); } } ca..
매번 기억은 하는데 쓰려고 하면 잊어버린다. #부모컴포넌트 부모 컴포넌트에서는 이렇게 작성을 해준다. getCheckedCode 는 부모 컴포넌트의 함수이고 addCheckCode는 자식컴포넌트에서 올라오는 값이다. #자식컴포넌트 newlyCheckedBox(code){ this.$emit('addCheckCode', code) }, 자식 컴포넌트에서 부모컴포넌트에 써준 '이벤트명'을 넣어준다. 여기서는 $emit 을 사용해야 한다. 같이 전달해야 하는 값이 있어서 옆에 code 를 작성해주었다.