Computer Science, asked by nityamsingh27, 6 months ago

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
• D
P
Sample Output : d= (68-80) = -12
First character is smaller​

Answers

Answered by itzFaReboy
4

OK, here we go,

class ASCII_Sum

{

static void teja(String st)

{

int l = st.length();

int s = 0;

for(int i = 1;i<l;i++)

{

char ch = st.charAt(i);

int p = (int)ch;

for(int j = 68,;j<=80;j++,h++)

{

if(p==j||p==h)

s=s+p;

else

s=s;

}

}

System.out.println(“Sum is “+s);

System.out.println(“Character of “+s+” is “+(char)s);

}

}

Search the output in (Java application app)

Answered by mruganeshraghav4
0

import java.util.*;

class ASC2

{

public static void main(String args[])

Scanner in=new scanmer(System.in);

system.out.println("First character")

char ch1=in.next().charAt(0)

system.out.println("Second character")

char ch2=in.next().charAt(0)

int d=(int)ch1-(int)ch2

if(d<0);

system.out.println("Firat character is samller");

if(d>0);

system.out.println("second character is smaller");

else;

system.out.println("Both are same");

}

}

Explanation:

out put= first characted:A

second character:F

First character is smaller

DOnt refer to the first one full wrong

Similar questions