0
How to make a java program in which i can place different numeric values of a - z and get output?
i want to make a simple java program in which i can place binary values of alphabets a - z. When i run it, it should ask me to type a sentence and after pressing enter should convert each letter into its binary value and dislplay the output.
4 Respostas
+ 3
Actually chars are numbers already, no need to convert them. And you can turn a number x into its binary counterpart with Integer.toBinaryString(x). Now if you want leading 0s it gets a bit more complicated, you can use something like this:
String.format("%8s", Integer.toBinaryString(x)).replace(" ", "0")
or you make your own function to turn a number into binary.
+ 2
make 2 arrays. 1 with the letters and one with the binary value for each letter.
when you input your sentence, send it thru a for loop, and for each letter in the for loop, make a new String with the binary value associated with the same array index for the binary value as the array index from the letter
+ 1
you have have to make it in two part ,
1st : one method which return the decimal value of alphabet like A=65 or a=97 then the and 2nd one method which return the binary of that alphabet's decimal number,.
eg
char value='A';
ans = giveAscii(value); // here ans = 65 will store,
FinalAns = giveBinary(ans); /*here the binary value of 65 will be returned and store , which is FinalAns = 01000001 : )*/
here giveAscii() and giveBinary() are method created by you😂 which return appropriate value as per your requirement.
+ 1
yea... that worked......
thanks