+ 3

Now this eating up my brain. How does the output come a. b. c. d.

Char ch Int x=97; Do { Ch=(char)x; System.out.println(ch + " "); If (x%10==0) Break; ++X; While(x<=100); }

14th Jul 2019, 11:40 AM
Justin
Justin - avatar
6 Answers
+ 7
When you convert an int to a char, what the char hold is followed by ASCII code. You can search for it and you will see that 97 is 'a', 98 is 'b' and so on until 100.
14th Jul 2019, 1:44 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 4
Man this is totally unexpected answer to the question The real output is coming because of ā€¢ascii values ā€¢addition of values Hope you get your answeršŸ‘Œ
14th Jul 2019, 12:17 PM
Jeffly
Jeffly - avatar
+ 4
I also have a question on this code. If you already have a do-while loop, why do you need an if-statment to stop it?
14th Jul 2019, 1:50 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 2
habe a look at the ascii table. where Ā“aĀ“=97, Ā“bĀ“=97 and so on
14th Jul 2019, 12:02 PM
pur80a
pur80a - avatar
+ 2
The if statement is used to terminate the loop when the integer value of the char is divisible by 10. As 'd' has an ASCII code of 100, the loop is terminated after printing 'd'.
15th Jul 2019, 9:29 AM
Sonic
Sonic - avatar
+ 1
Its all about ASCII (American Standard Characters Information Interchange)
15th Jul 2019, 12:53 AM
Nouman Bin Sami
Nouman Bin Sami - avatar