0% found this document useful (0 votes)
10 views4 pages

Class10 Computer Java Solutions

The document contains Java solutions for various programming problems suitable for Class 10 Computer Applications. It includes code for checking Armstrong numbers, counting vowels and consonants, determining palindrome strings, calculating factorials using recursion, identifying special two-digit numbers, and displaying patterns. Each solution is presented with a brief explanation of its functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Class10 Computer Java Solutions

The document contains Java solutions for various programming problems suitable for Class 10 Computer Applications. It includes code for checking Armstrong numbers, counting vowels and consonants, determining palindrome strings, calculating factorials using recursion, identifying special two-digit numbers, and displaying patterns. Each solution is presented with a brief explanation of its functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Class 10 – Computer Applications –

Section C Solutions
Question 3: Armstrong Number

import [Link];

public class ArmstrongNumber {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int original = num;
int result = 0;

while (num > 0) {


int digit = num % 10;
result += digit * digit * digit;
num /= 10;
}

if (result == original)
[Link](original + " is an Armstrong number");
else
[Link](original + " is not an Armstrong number");
}
}

Question 4: Count Vowels and Consonants

import [Link];

public class VowelConsonantCount {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
char[] letters = new char[20];
int vowels = 0, consonants = 0;

[Link]("Enter 20 letters:");
for (int i = 0; i < 20; i++) {
letters[i] = [Link]([Link]().charAt(0));
if ("AEIOU".indexOf(letters[i]) != -1)
vowels++;
else if (letters[i] >= 'A' && letters[i] <= 'Z')
consonants++;
}

[Link]("Vowels: " + vowels);


[Link]("Consonants: " + consonants);
}
}

Question 5: Palindrome String

import [Link];

public class PalindromeString {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a string: ");
String str = [Link]();
String reversed = "";

for (int i = [Link]() - 1; i >= 0; i--)


reversed += [Link](i);

if ([Link](reversed))
[Link]("Palindrome");
else
[Link]("Not a Palindrome");
}
}

Question 6: Factorial using Recursion

import [Link];

public class FactorialRecursion {


public static int factorial(int n) {
if (n <= 1)
return 1;
return n * factorial(n - 1);
}

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
[Link]("Factorial: " + factorial(num));
}
}

Question 7: Special Two-Digit Number

import [Link];

public class SpecialTwoDigit {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a two-digit number: ");
int num = [Link]();
int tens = num / 10;
int units = num % 10;

int sum = tens + units;


int product = tens * units;

if (sum + product == num)


[Link]("Special 2 - digit number");
else
[Link]("Not a special two-digit number");
}
}

Question 8: Pattern Display

public class PatternDisplay {


public static void main(String[] args) {
for (int i = 1; i <= 4; i++) {
char ch;
if (i == 1) ch = 'A';
else if (i == 2) ch = 'a';
else if (i == 3) ch = 'B';
else ch = 'b';
for (int j = 1; j <= 5; j++) {
[Link](ch + " ");
}
[Link]();
}
}
}

You might also like