[Student] Lombok 적용(@Getter, @Setter)
로 배열 수정 -.." data-og-host="yermi.tistory.com" data-og-source-url="https://yermi.tistory.com/85" data-og-url="https://yermi.tistory.com/85" data-og-image="https://scrap.kakaocdn.net/dn/oIt3J/..
yermi.tistory.com
- String.format을 이용한 출력 양식 정리
[꿀팁] 이클립스(Eclipse)에서 한글 출력 밀리지 않게 하기[String.format을 이용한 한글 자리수 맞춰
- 이클립스(Eclipse)에서 한글 출력 밀리지 않게 하기 이클립스(Eclipse)에서 사용하고 있는 UTF-8에서는 반각문자는 1Byte, 전각문자는 2Byte로 등록되어있다. 즉, 영문자, 숫자(반각문자)는 1Byte, 한글(
yermi.tistory.com
- service : class StudentServiceImpl
package service;
public class StudentServiceImpl implements StudentService {
// 내용 생략
public void list() { // 조회 기능 구현
System.out.println("조회 기능 구현");
// System.out.printf(" 학번 \t 이름 \t 국어 \t 영어 \t 수학 \t 총점 \t 평균 %n");
System.out.println(String.format("%s%s%s%s%s%s%s"
, Test.convert("학번", 8)
, Test.convert("이름", 10)
, Test.convert("국어", 5)
, Test.convert("영어", 5)
, Test.convert("수학", 5)
, Test.convert("총점", 5)
, Test.convert("평균", 9)));
System.out.printf("===================================================%n");
for (Student s : students) {
System.out.print(Test.convert(s.getNo(), 8));
System.out.print(Test.convert(s.getName(), 10));
System.out.print(Test.convert(s.getKor()+"", 5));
System.out.print(Test.convert(s.getEng()+"", 5));
System.out.print(Test.convert(s.getMat()+"", 5));
System.out.print(Test.convert(s.sum()+"", 5));
System.out.print(Test.convert(s.avg()+"", 9));
System.out.println();
}
}
// 내용 생략
// 전각문자 개수를 세주는 메서드
private static int getKorCnt(String kor) {
int cnt = 0;
for (int i = 0 ; i < kor.length() ; i++) {
if (kor.charAt(i) >= '가' && kor.charAt(i) <= '힣') {
cnt++;
}
} return cnt;
}
// 전각문자의 개수만큼 문자열 길이를 빼주는 메서드
public static String convert(String word, int size) {
String formatter = String.format("%%%ds", size -getKorCnt(word));
return String.format(formatter, word);
}
}
[Student] 직렬화를 사용한 데이터 영속화
[Student] String.format을 이용한 출력 양식 정리 [Student] Lombok 적용(@Getter, @Setter) 로 배열 수정 -.." data-og-host="yermi.tistory.com" data-og-source-url="https://yermi.tistory.com/85" data-og-url="https://yermi.tistory.com/85" data-og
yermi.tistory.com