Advertisement
desislava_topuzakova

04. ASCII Combinations

May 21st, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ASCIICombinations {
  4. public static void main(String[] agrs) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8.  
  9. int sumDigits = 0;
  10. int sumSmallLetters = 0;
  11. int sumCapitalLetters = 0;
  12. int sumOthers = 0;
  13.  
  14. int max = 0;
  15.  
  16. String digits = "";
  17. String smallLetter = "";
  18. String capitalLetter = "";
  19. String others = "";
  20.  
  21. for (int i = 0; i < n; i++) {
  22. char symbol = scanner.nextLine().charAt(0);
  23.  
  24. if ((int) symbol >= 48 && (int) symbol <= 57) {
  25. sumDigits += (int) symbol;
  26. digits += symbol;
  27. } else if ((int) symbol >= 97 && (int) symbol <= 122) {
  28. sumSmallLetters += (int)symbol;
  29. smallLetter += symbol;
  30. } else if ((int) symbol >= 65 && (int)symbol <= 90) {
  31. sumCapitalLetters += (int)symbol;
  32. capitalLetter += symbol;
  33. } else {
  34. sumOthers += (int)symbol;
  35. others += symbol;
  36. }
  37. }
  38.  
  39. max = Math.max(Math.max(sumDigits, sumSmallLetters), Math.max(sumCapitalLetters, sumOthers));
  40. System.out.printf("Biggest ASCII sum is:%d%n", max);
  41.  
  42. if(sumDigits == max){
  43. System.out.println("Combination of characters is:" + digits);
  44. }else if (sumCapitalLetters == max){
  45. System.out.println("Combination of characters is:" + capitalLetter);
  46. }else if (sumSmallLetters == max) {
  47. System.out.println("Combination of characters is:" + smallLetter);
  48. }else if (sumOthers == max){
  49. System.out.println("Combination of characters is:" + others);
  50. }
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement