Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ASCIICombinations {
- public static void main(String[] agrs) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int sumDigits = 0;
- int sumSmallLetters = 0;
- int sumCapitalLetters = 0;
- int sumOthers = 0;
- int max = 0;
- String digits = "";
- String smallLetter = "";
- String capitalLetter = "";
- String others = "";
- for (int i = 0; i < n; i++) {
- char symbol = scanner.nextLine().charAt(0);
- if ((int) symbol >= 48 && (int) symbol <= 57) {
- sumDigits += (int) symbol;
- digits += symbol;
- } else if ((int) symbol >= 97 && (int) symbol <= 122) {
- sumSmallLetters += (int)symbol;
- smallLetter += symbol;
- } else if ((int) symbol >= 65 && (int)symbol <= 90) {
- sumCapitalLetters += (int)symbol;
- capitalLetter += symbol;
- } else {
- sumOthers += (int)symbol;
- others += symbol;
- }
- }
- max = Math.max(Math.max(sumDigits, sumSmallLetters), Math.max(sumCapitalLetters, sumOthers));
- System.out.printf("Biggest ASCII sum is:%d%n", max);
- if(sumDigits == max){
- System.out.println("Combination of characters is:" + digits);
- }else if (sumCapitalLetters == max){
- System.out.println("Combination of characters is:" + capitalLetter);
- }else if (sumSmallLetters == max) {
- System.out.println("Combination of characters is:" + smallLetter);
- }else if (sumOthers == max){
- System.out.println("Combination of characters is:" + others);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement