info@meritcampus.com    +91-85006-22255
...
`

Print statement1898
What will be the output of the following program?
`public class CanYou {    public static void main(String args[]) {        System.out.print("" + 9 + 7 + " ");        System.out.print(9 + "" + 7 + " ");        System.out.print(9 + 7 + "" + " ");        System.out.print(9 + 7 + " ");        System.out.print("1" + 9 + 7 + " ");        System.out.print(9 + 7);    }}`

 A. 97 97 16 16 197 16 B. 16 97 16 16 116 16 C. 16 16 16 16 116 16 D. Some other output E. Compilation Error or Runtime Error
Topic:

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

B

Posted by Iba Ha Kadam-an    2014-07-30 12:43:17

Values other than strings are not concatenated but are evaluated arithmetically.

Posted by Iba Ha Kadam-an    2014-07-30 12:44:55

ans is a

Posted by Sareesh Rayapati    2014-07-30 12:47:17

B is ans as 2nd SOP jst prnts 9 7 n 5th SOP "1"+16 ie 116

Posted by Shabaaz Shaikz    2014-07-30 12:47:52

b.

Posted by Shubham Bansal    2014-07-30 12:54:46

ans B, the operand "+" is used for concatination and addition of a two integer ,Strings ect...

Posted by Damu Surya    2014-07-30 13:17:25

b

Posted by Sai Nadh    2014-07-30 13:36:22

there only two values are concatnate 9+7=16,9+""+7=97 becase arithematic operation not evaluted strings are not performed,9+7=16,9+7=16,1""9+7=116,9+7=16

Posted by Sai Nadh    2014-07-30 13:39:20

above operation apply "1"+9+7=116 strings are not calcuted in arithmetic opertion

Posted by Sai Nadh    2014-07-30 13:40:35

option A

Posted by Vino Krishnan    2014-07-30 15:43:18

No winner for this dose. Correct option is 'A' :(.

Posted by Merit Campus    2014-07-31 04:46:08

Ela

Posted by Sai Nadh    2014-07-31 04:51:26

As explained by Jayson Loyola Rael Ramos and Sai Nadh, whether the integers are added arithmetically or are they concatenated is dependent on the type present before that. In case of first print, since we have an empty string before, they will be concatenated to the string, where as for 3rd, 4th and 6th prints it will just sum up arithmetically. For 1st and 5th line, since we have string in the beginning, it will be string concatenation only.

Posted by Merit Campus    2014-07-31 08:59:39

If we want the numbers to be added arithmetically, then we can include them in parenthesis.

Posted by Merit Campus    2014-07-31 09:00:17