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");
Decorator pattern BufferedReader sc = new BufferedReader(new FileReader("src" + File.separator + "csv_input" + File.separator + "students.csv")); We have various methods to choose for File I/O such as FileReader, BufferdReader, BufferedWriter, PrintWrite etc. The decorator pattern allows applying more than one method for File I/O without altering. File.separator File.separator enables to work on..
students.csv id,name 1,A 2,B 3,C public class StudentInfo { private int id; private String name; public StudentInfo(int id, String name){ this.id = id; this.name = name; } public int studentId(){ return id; } @Override public String toString(){ return "Student Id: " + this.id + ", " + "name: " + this.name + "\n"; } } public class Main { public static void main(String[] args) throws FileNotFoundE..
asList() is used to convert Array to List. This example takes an Integer type array as a parameter and it needs to remove duplicate numbers as a result. But, when you use asList(), the type of array should be Object type wrappers. Because Generics only works for a reference type. List 는 Generic 이기에 오직 reference type만을 전달 받는다. 그래서 asList()에 primitive 타입이 올 수 없게 된다. Example Code import java.util.*..
enum 열거형 - enum은 연관된 상수들의 집합(a set of named constants.)으로 열거 순서에 따라 index번호를 부여받는다. - enum은 private constructor가 default이기에 public생성자의 생성이 금지된다 인스턴스를 만들 수 없다는 것은 즉, 다른 용도의 사용을 금한다는 의미이다. Example Code enum Fruit{ APPLE, PEACH, BANANA; Fruit(){ System.out.println("Constructor"); } } public class Main { public static void main(String[] args) { Fruit type = Fruit.APPLE; switch(type){ case APPLE: Sys..
- Total
- Today
- Yesterday
- 알고리즘
- repeat()
- math.max
- java
- math.abs
- algorithm
- HackerRank Algorithm
- easy javascript algorithm
- hackerrank javascript solution
- 프로그래머스 알고리즘문제
- compareTo()
- Javascript Algorithm
- 프로그래머스 알고리즘
- hackerrank javascript
- javascript
- easy algorithm
- code refactoring
- Collection Framework
- ... in Javascript
- spring boot application
- Object type casting
- substring()
- equals()
- hackerrank
- hackerrank solution
- HashMap
- rest parameter
- C++
- 프로그래머스
- string class in java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |