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

Answered By
3 Likes
Related Questions
State the data type and value of res after the following is executed:
char ch = '9'; res= Character.isDigit(ch);The method to convert a String to double is:
- String.toDouble()
- Double.Parsedouble()
- Double.parseDouble(String)
- Double.parseDouble()
Differentiate between boxing and unboxing.
The method to convert a lowercase character to uppercase is:
- String.toUpperCase( )
- Character.isUppercase( char )
- Character.toUpperCase( char )
- toUpperCase ( )