Baekjoon Online Judge - 10820
Review
- 문자열 갯수가 정해지지 않아 입력 받기가 어려웠던 문제.
hasNextLine()
하나 배웠다.
Code (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 32 33 34 35 36
| import java.util.Scanner;
public class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); String input; int upper; int lower; int num; int space; while(sc.hasNextLine()) { upper = 0; lower = 0; num = 0; space = 0; input = sc.nextLine(); for(int i = 0; i < input.length(); i++) { int c = (int)input.charAt(i); if(c>= 97 && c <=122) { lower++; } else if(c>= 65 && c <=90) { upper++; } else if(c>= 48 && c <=57 ) { num++; } else if(c==32) { space++; } } System.out.println(lower + " " + upper + " " + num + " " + space); } sc.close(); } }
|