Computer Applications
Define a class to declare a character array of size 20, accept the characters into the array and perform the following:
(i) print each character in capital letter.
(ii) print sum of the ASCII value of all the elements.
Java
Java Arrays
20 Likes
Answer
import java.util.Scanner;
public class KboatSDACharSum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
char arr[] = new char[20];
System.out.println("Enter characters in array:");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.next().charAt(0);
}
System.out.println("Characters in capital letters:");
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
char ch = Character.toUpperCase(arr[i]);
System.out.print(ch + " ");
}
System.out.println();
System.out.println("ASCII Sum = " + sum);
}
}Output

Answered By
5 Likes
Related Questions
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033
Define a class to accept values into 4x4 array and find and display the sum of each row.
Example:
A[][]={{1,2,3,4},{5,6,7,8},{1,3,5,7},{2,5,3,1}}
Output:
sum of row 1 = 10 (1+2+3+4) sum of row 2 = 26 (5+6+7+8) sum of row 3 = 16 (1+3+5+7) sum of row 4 = 11 (2+5+3+1)