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
1 Like
Related Questions
String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);
What is value of x?
Chhavi wants to check whether a character variable
ch
contains an uppercase letter (A-Z).She writes the following statement, which is incorrect:
if (ch == "A" && ch == "Z")
What will be the correct statement?
A.
if (Character.isUpperCase(ch))
B.if (ch >= 65 && ch <= 90)
C.if (ch >= 'A' && ch <= 'Z')
The method to convert a lowercase character to uppercase is:
- String.toUpperCase( )
- Character.isUppercase( char )
- Character.toUpperCase( char )
- toUpperCase ( )
Give the output of the following code:
String P = "20", Q ="19"; int a = Integer.parseInt(P); int b = Integer.valueOf(Q); System.out.println(a+""+b);