Menu
Topics Index
...
`

Print ascii codes and numbers


If you need explanation Read this topic

If you need Answer Take test on this topic

Print ascii codes and numbers
What will be the output of the following program?
public class SamsungDuos
{
    public static void main(String[] args)
    {
        char first;
        int second;
        for (first = 98, second = 'b'; first < 106 || second <= 106; second++, first++)
        {
            int temp = 0, temp1 = 0;
            temp1 = second - 30;
            temp += (first - 30);
            String str = "106";
            System.out.print(temp1 + "--" + (char) temp + (!str.equals(Integer.toString(second)) ? ", " : " "));
        }
    }
}

A. 68--D, 69--E, 70--F, 71--G, 72--H, 73--I, 74--J, 75--K, 76--L
B. 68--D, 69--E, 70--F, 71--G, 72--H, 73--I, 74--J, 75--K,
C. 68--B, 69--C, 70--D, 71--E, 72--F, 73--G, 74--H, 75--I, 76--J
D. Compilation Error because type mismatch
E. Compilation Error or Runtime Error for some other reason
Topic: Java equals method vs == Operator

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is A

Posted by Ramya Reddy Addulla    2014-10-10 12:38:43


a

Posted by Shubham Bansal    2014-10-10 12:40:30


Ans is A...
here we have one local char variable first and another integer varible second...

local varibles dont have any default values we must initilize bfore usage..
in for loop we are assigning first as 98 ans second as 'b'

we put condtion usng OR(||) if any one condtion s true than contions wil be true
in for loop we are creating 2 local varibles named as temp,temp1

every time we are subtracting 30 from the second 'b'=98
98-30=68;
temp wil becom 68
temp1+=first-30
temp1=wil be 68
next we are type casting temp into char means it wil print its equlnt char...68--D...69--F so on

int string atr we are taking 106 if second equls 106 we are printing : else , wil get printed...

Posted by Uday Kumar    2014-10-10 12:49:02


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Šâí Râm for the 'Popular Comment'. The 'lucky liker' is Mariam Leo. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-10-13 05:01:22


© meritcampus 2019

All Rights Reserved.

Open In App