Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test11_03;
- import java.util.Scanner;
- public class ASCII {
- public static void main(String[] agrs) {
- Scanner scanner = new Scanner(System.in);
- int symbols = Integer.parseInt(scanner.nextLine());
- int sum1 = 0;
- int sum2 = 0;
- int sum3 = 0;
- int sum4 = 0;
- int maxSum = 0;
- String max1 = "";
- String max2 = "";
- String max3 = "";
- String max4 = "";
- for (int i = 0; i < symbols; i++) {
- char a = scanner.nextLine().charAt(0);
- if ((int) a >= 48 && (int) a <= 57) {
- sum1 += (int) a;
- max1 += "" + a;
- if (sum1 > maxSum) {
- maxSum = sum1;
- }
- } else if ((int) a >= 65 && (int) a <= 90) {
- sum2 += (int) a;
- max2 += "" + a;
- if (sum2 > maxSum) {
- maxSum = sum2;
- }
- } else if ((int) a >= 97 && (int) a <= 122) {
- sum3 += (int) a;
- max3 += "" + a;
- if (sum3 > maxSum) {
- maxSum = sum3;
- }
- } else {
- sum4 += (int) a;
- max4 += "" + a;
- if (sum4 > maxSum) {
- maxSum = sum4;
- }
- }
- }
- System.out.println("Biggest ASCII sum is:" + maxSum);
- if (maxSum == sum1) {
- System.out.println("Combination of characters is:" + max1);
- } else if (maxSum == sum2) {
- System.out.println("Combination of characters is:" + max2);
- } else if (maxSum == sum3) {
- System.out.println("Combination of characters is:" + max3);
- } else if (maxSum == sum4) {
- System.out.println("Combination of characters is:" + max4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement