Advertisement
desislava_topuzakova

ASCII

Mar 15th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package test11_03;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ASCII {
  6.     public static void main(String[] agrs) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int symbols = Integer.parseInt(scanner.nextLine());
  9.         int sum1 = 0;
  10.         int sum2 = 0;
  11.         int sum3 = 0;
  12.         int sum4 = 0;
  13.         int maxSum = 0;
  14.         String max1 = "";
  15.         String max2 = "";
  16.         String max3 = "";
  17.         String max4 = "";
  18.  
  19.         for (int i = 0; i < symbols; i++) {
  20.             char a = scanner.nextLine().charAt(0);
  21.             if ((int) a >= 48 && (int) a <= 57) {
  22.                 sum1 += (int) a;
  23.                 max1 += "" + a;
  24.                 if (sum1 > maxSum) {
  25.                     maxSum = sum1;
  26.                 }
  27.             } else if ((int) a >= 65 && (int) a <= 90) {
  28.                 sum2 += (int) a;
  29.                 max2 += "" + a;
  30.                 if (sum2 > maxSum) {
  31.                     maxSum = sum2;
  32.                 }
  33.             } else if ((int) a >= 97 && (int) a <= 122) {
  34.                 sum3 += (int) a;
  35.                 max3 += "" + a;
  36.                 if (sum3 > maxSum) {
  37.                     maxSum = sum3;
  38.                 }
  39.             } else {
  40.                 sum4 += (int) a;
  41.                 max4 += "" + a;
  42.                 if (sum4 > maxSum) {
  43.                     maxSum = sum4;
  44.                 }
  45.  
  46.             }
  47.         }
  48.         System.out.println("Biggest ASCII sum is:" + maxSum);
  49.         if (maxSum == sum1) {
  50.             System.out.println("Combination of characters is:" + max1);
  51.         } else if (maxSum == sum2) {
  52.             System.out.println("Combination of characters is:" + max2);
  53.         } else if (maxSum == sum3) {
  54.             System.out.println("Combination of characters is:" + max3);
  55.         } else if (maxSum == sum4) {
  56.             System.out.println("Combination of characters is:" + max4);
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement