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
A class teacher wants to arrange the names of her students in alphabetical order. Define a class NameSorter that stores the given names in a one-dimensional array. Sort the names in alphabetical order using Bubble Sort technique only and display the sorted names.
Aryan, Zoya, Ishaan, Neha, Rohan, Tanya, Manav, Simran, Kabir, Pooja
public class NameSorter { void bubbleSort(String names[]) { int len = names.length; _______(1)_________ { _______(2)_________ { _______(3)_________ { String t = names[j]; _______(4)_________ _______(5)_________ } } } } public static void main(String[] args) { String arr[] = {"Aryan", "Zoya", "Ishaan", "Neha", "Rohan", "Tanya", "Manav", "Simran", "Kabir", "Pooja" }; NameSorter obj = new NameSorter(); obj.bubbleSort(arr); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"}; System.out.println(color[2].length());
- 6
- 5
- 3
- 2
Name the below structure:
- One dimensional array
- Two Dimensional array with 4 rows and 5 columns
- Three dimensional array
- Two Dimensional array with 5 rows and 4 columns
The statement used to find the total number of Strings present in the string array String s[] is:
- s.length
- s.length()
- length(s)
- len(s)