KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Write a Java program to accept a character and print all the characters following it in the reverse order(till a).

Sample input:
If the character entered is d.

Sample output:
d
c
b
a

Java

Java Library Classes

2 Likes

Answer

import java.util.Scanner;

public class KboatReverse
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a letter: ");
        char ch = in.next().charAt(0);
        
        if (Character.isLetter(ch)) {
            ch = Character.toLowerCase(ch);
            for (char x = ch; x >= 'a'; x--) {
                System.out.println(x);
            }
        }
        else {
            System.out.println("Invalid input");
        }
    }
}

Output

BlueJ output of Write a Java program to accept a character and print all the characters following it in the reverse order(till a). Sample input: If the character entered is d. Sample output: d c b a

Answered By

2 Likes


Related Questions