JAVA/JAVA 공부

    JAVA/JAVA 공부

    [java] 날자 출력 형식 설정하기 (포맷 형식 설정하기) - DateTimeFormatte Class

    LocalDate now = LocalDate.now(); System.out.println(now); //2021-08-26 //날짜 포맷 형식 설정하기 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyy/MM/dd"); System.out.println(now.format(formatter)); //2021/08/26

    JAVA/JAVA 공부

    [java] 난수 출력하기 - x부터 y까지 난수 발생하기

    기본적으로 난수는 0부터 1.0까지 실수형으로 출력한다. double num = Math.random(); System.out.println(num); 정수형으로 출력하고 싶을때는 자료형을 정수형으로 바꿔주고 10을 곱한다음 1을 더해주면 된다. 1부터 10까지 난수 출력하기 int num = (int)(Math.random() * 10) + 1; System.out.println(num); 5부터 100까지 정수 출력하기 int num1 = (int)(Math.random() * 96) + 5; System.out.println(num1); x부터 y까지 정수를 출력할 때 곱하는 숫자는 = y -x + 1 더하는 숫자는 x이다.

    JAVA/JAVA 공부

    [java] "equals의 재정의"에서 String과 그 외 자료형 설정

    public boolean equals(Object obj) { //자료형은 Object이지만 전달받는 데이터는 car형이기 때문에 다운캐스팅해준다. Car car = (Car) obj; //여기에서 사용되는 equals는 Object에 정의된게 아니라 String에 오버라이징된 equals이기 때문에 //String자료형에서는 예외적으로 주소가 아닌 문자열을 비교할 수 있다. if (this.name.equals(car.name) //--> String의 equals && this.color.equals(car.color) && this.direction == car.direction //--> Object의 equals && this.speed == car.speed) { return true; }e..