Menu
Topics Index
...
`

Print numbers using print and println2983


If you need explanation Read this topic

If you need Answer Take test on this topic

Print numbers using print and println2983
What will be the output of the following program?
class TestingProgram
{
    public static void main(String args[])
    {
        System.out.print("The output is : ");
        System.out.println("1" + "3");
    }
}

A. The output is : 
13
B. The output is : 13
C. The output is : 4
D. Compilation Error
Topic: Java String concatenation - concat() Method In Java

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.

The answer is a,because in the second println 1 & 3 are taken as text so the   operator will join two string in to one string and println will insert next line and print 13 as string

Posted by Deion Davis    2015-01-28 09:59:42


answer is B  here execution starts with main() here System.out.print("the output is:") here  print() method leaves the cursor on the same line after printing the text ie "the output is:"next stmt System.out.println("1"+"3") here +operator is used for concatenation of two strings it prints "13" here println() statement  positions the cursor onto the next line after printing the desired text  ie after printing 13  cursor points to next line .there fore the output is printed as "the output is:13"

Posted by Ramya Reddy Addulla    2015-01-28 10:32:24


Ans is Option B..Execution starts from main() method first it will print                  "The Output is:" after that cursor is in the same line because we are using System.out.print("") statement using print statement after printing value cursor will be on the same line and then we  have println statement which print 13 because here we are doing concatanation using + operator so it will print 13 which is string value after that cursor will go to next line bcz we are using println stmt so Option is The Output is : 13

Posted by Bhagi Bhagyasri    2015-01-28 13:34:21


b ..

Posted by Shubham Bansal    2015-01-28 19:59:02


This dose is now closed and the winners are Ramya Reddy Addulla,  for 'First Correct Comment', Bhagi Bhagyasri,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Mânïshå Mùlchåndânï. 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    2015-01-29 06:17:28


© meritcampus 2019

All Rights Reserved.

Open In App