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
2 Likes
Related Questions
The method to convert a lowercase character to uppercase is:
- String.toUpperCase( )
- Character.isUppercase( char )
- Character.toUpperCase( char )
- toUpperCase ( )
Predict the output of the following code snippet:
char ch='B', char chr=Character.toLowerCase(ch); int n=(int)chr-10; System.out.println((char)n+"\t"+chr);
Which of the following is the correct method to convert a String to a
double
in Java?Assertion (A): Integer class can be used in the program without calling a package.
Reason (R): It belongs to the default package java.lang.
- Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
- Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion(A)
- Assertion (A) is true and Reason (R) is false
- Assertion (A) is false and Reason (R) is true