Computer Applications
Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit numbers entered. Display them separately.
Example:
Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}
Output:
Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19
Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107
Java
Java Arrays
ICSE 2023
55 Likes
Answer
import java.util.Scanner;
public class KboatDigitSum
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int oneSum = 0, twoSum = 0, d = 0;
int arr[] = new int[10];
System.out.println("Enter 10 numbers");
int l = arr.length;
for (int i = 0; i < l; i++)
{
arr[i] = in.nextInt();
}
for (int i = 0; i < l; i++)
{
if(arr[i] >= 0 && arr[i] < 10 )
oneSum += arr[i];
else if(arr[i] >= 10 && arr[i] < 100 )
twoSum += arr[i];
}
System.out.println("Sum of 1 digit numbers = "+ oneSum);
System.out.println("Sum of 2 digit numbers = "+ twoSum);
}
}
Variable Description Table
Program Explanation
Output
![BlueJ output of Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit numbers entered. Display them separately. Example: Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1} Output: Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19 Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107 BlueJ output of Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit numbers entered. Display them separately. Example: Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1} Output: Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19 Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107](https://cdn1.knowledgeboat.com/img/abp10/1/2023-p8.jpg)
Answered By
19 Likes
Related Questions
Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending order. Display the sorted array and original array.
Define a class to overload the function print as follows:
void print() - to print the following format
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.Define a class to accept a String and print the number of digits, alphabets and special characters in the string.
Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1Define a class to accept values into an array of double data type of size 20. Accept a double value from user and search in the array using linear search method. If value is found display message "Found" with its position where it is present in the array. Otherwise display message "not found".