Class 10 Library Classes Programs Solved

WAP in Java to input a character. Find and display the next 10th character in the ASCII table.

import java.util.Scanner;
class Prog1
{
    static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a character:");
        char ch=sc.next().charAt(0); //for character input
        ch+=10; //next 10th character
        System.out.println("Next 10th character is:"+ch);
    }
}

WAP in Java to generate all the alternate letters in the range of letters from A to Z

class Prog2
{
    static void main()
    {
        for(char ch='A';ch<='Z';ch+=2){
            System.out.println(ch);
        }
    }
}

WAP to input a set of 20 letters. Convert each letters into uppercase. Find and display the number of vowels and number of consonants present in the set of given letters.

import java.util.Scanner;
class Prog3
{
    static void main()
    {
        Scanner sc=new Scanner(System.in);
        //number of vowels and consonants
        int v=0,c=0;
        for(int i=1;i<=20;i++)
        {
            System.out.println("Enter a character:");
            char ch=sc.next().charAt(0); //char input
            ch=Character.toUpperCase(ch);
            if(Character.isLetter(ch))
            {
                if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
                {
                    v=v+1; //increment vowel
                }
                else{
                    c=c+1; //increment consonant
                }
            }
        }
        System.out.println("The number of vowels:"+v);
        System.out.println("The number of consonants:"+c);
    }
}

WAP to input two characters from the keyboard. Find the difference between the ascii codes. Display the following messages.

  • If D=0, Both characters are same
  • If D<0, ASCII value of the first character is less than second
  • If D>0, ASCII value of the second character is more than the first
  • Example: Y (ASCII = 89)
  • Z (ASCII = 90)
  • Sample Output: d= 89 – 90 = -1
import java.util.Scanner;
class difference
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter two characters:");
        char ch=sc.next().charAt(0); //first character
        char ch2=sc.next().charAt(0); //second character
        int d = ch-ch2; //difference
        System.out.println("The difference is "+d);
        if(d==0)
            System.out.println("Both characters are same");
        else if(d<0)
            System.out.println("ASCII value of the first character is less than second");
        else
            System.out.println("ASCII value of the second character is more than the first");
    }
}

WAP to input a set of any 10 integer numbers. Find the sum and product of the numbers. Join the sum and product to form

a single number. Display the concatenated number.

Example:

  • Sum=245
  • Product=1346
  • Concatenated number=2451346
import java.util.*;
class combine
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        int s=0;
        long p=1; //sum and product variables
        System.out.println("Enter any 10 numbers:");
        for(int i=1;i<=10;i++)
        {
            int n = sc.nextInt(); //take input
            s=s+n; //sum of the integers
            p=p*n;
        }
        //first way
        String result = Integer.toString(s)+Long.toString(p);
        //second way
        String result2 = String.valueOf(s) + String.valueOf(p);
        //third way
        String result3 = ""+s+p;
        System.out.println("Combined number is="+result);
    }
}

Write a menu driven program to generate the uppercase letters from Z to A and lowercase letters from a to z,as per user choice.

import java.util.*;
class menu1
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 1 to generate uppercase letters\nEnter 2 to generate lowercase letters");
        int ch=sc.nextInt();
        switch(ch){
            case 1:
                System.out.println("Uppercase letters are:");
                for(char c='Z';c>='A';c--)
                    System.out.println(c);
                break;
            case 2:
                System.out.println("Lowercase letters are:");
                for(char c='a';c<='z';c++)
                    System.out.println(c);
                break;
            default: System.out.println("Wrong Choice");
        }
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top