hasNextInt() Use hasNextInt() to check if it's integer or not while (!keyboard.hasNextInt()) { MenuViewer.keyboard.next(); //discard System.out.println("You entered character. Please, Enter a number to choose"); } Example Code while (true) { //try catch 구문이 while안에 있어야 에러처리가 끝나도 다시 메뉴를 선택할 수 있어. try { MenuViewer.menuViewer(); //Static method 이기 때문에 class name으로 호출 while (!MenuViewer.keyboard.has..
hashCode() and equals() - 서로 다른 객체는 각자 다른 주소값을 가지고 있기에 각자의 hashCode를 가지게 된다. - equals()는 최상위 Object class에 속해 있어서 Java Class들이 overriding 하는 것이 가능. - primitive type은 내용이 같은지 reference 는 가리키는 주소가 같은지 비교해주는데 overriding을 통해서 이 점을 수정가능. - HashSet의 equals()는 내용이 동일하면 true를 반환 - HashSet의 add()는 데이터의 입력이 가능(hashSet에 동일한 data가 존재하지 않는다)하면 true, 요소가 이미 존재하면 false를 반환 - equals() 만 overriding 할 경우 같은 내용이지만..
Singleton pattern It creates only one instance of a class, not allow to create a 2nd instance. How to create a Singleton pattern 1. Create a 'static' object of a class 2. Create private constructor to prevent that a user creates an instance with a default constructor. ※ The default constructor is called when an instance is created. the default constructor is public by default. 3. Create a 'stati..
A user types 'integer value' and 'Enter', but nextInt() does not use the end of the input, which is 'Enter' so that it leaves in the buffer. If nextLine() is used after nextInt(), the remainder causes an error. Because nextLine() is the method that reads data until the 'Enter' input. To remove the last input(Enter), simply use nextLine() to terminate the line. nextInt()메서드 다음에 nextLine()메서드가 온다면..
Simply use String.format(,) to format double output using BufferdWrite. Example output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file.getPath()), StandardCharsets.UTF_8)); output.write("Total Average: " + "\t" + "\t" + String.format("%.2f",average) + "%" + "\n" + "\n");
- Total
- Today
- Yesterday
- equals()
- java
- spring boot application
- hackerrank javascript solution
- hackerrank
- string class in java
- hackerrank solution
- 프로그래머스 알고리즘문제
- code refactoring
- algorithm
- substring()
- HashMap
- Javascript Algorithm
- math.max
- compareTo()
- rest parameter
- hackerrank javascript
- 알고리즘
- ... in Javascript
- 프로그래머스
- repeat()
- C++
- Object type casting
- 프로그래머스 알고리즘
- easy javascript algorithm
- javascript
- Collection Framework
- easy algorithm
- math.abs
- HackerRank Algorithm
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |