(Hint:
then display A]
6. Write a program to input two characters from the keyboard. Find the difference (d)
between their ASCII codes. Display the following messages:
If d=0
: both the characters are same.
If d<0
: first character is smaller.
If d>0
: second character is smaller.
Sample Input
Р
Sample Output : d= (68-80) = -12
First character is smaller
: D
Answers
Answered by
21
Answer:
import java.util.Scanner;
public class KboatASCIIDiff
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first character: ");
char ch1 = in.next().charAt(0);
System.out.print("Enter second character: ");
char ch2 = in.next().charAt(0);
int d = (int)ch1 - (int)ch2;
if (d > 0)
System.out.println("Second character is smaller");
else if (d < 0)
System.out.println("First character is smaller");
else
System.out.println("Both the characters are same");
}
}
Similar questions