Menu
Topics Index
...
`

Print statement1130


If you need explanation Read this topic

If you need Answer Take test on this topic

Print statement1130
What will be the output of the following program?
public class PrintStatementsOutput
{
    public static void main(String[] args)
    {
        String str = "Hai friend how are you";

        System.out.print(str);
        System.out.println();
        System.out.printf(str, str);
        System.out.println();
        System.out.format(str, str, str);
    }
}

A. Hai friend how are you
Hai friend how are youHai friend how are you
Hai friend how are youHai friend how are youHai friend how are you
B. Hai friend how are you
Hai friend how are you
Hai friend how are you
C. Hai friend how are you
Hai friend how are you 
Hai friend how are you
Hai friend how are you Hai friend how are you Hai friend how are you
D. Compilation Error
E. Runtime Error
Topic: Formatting Strings And Characters By Using Formatter

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 C..here we have concept of the printing the Strings on the Console..
here we took the String literal with the content "Hai friend how are you"
* first we are printing the String using the S.o.print() so it will print the String and cursor will place at the next location,and next we use the S.o.println() so cursor will moves to the next line
Next we are using the printf() by separating with the ,so here it will ingonre the one string, if we use format specifiers than it will print both, simialr to the format() also

Posted by Uday Kumar    2015-03-05 03:46:46


option is C
here in main() function we creating a string name str="Hai friend how are you";
here some statements are mentioned
1 System.out,print(str)>it will prints the string str conatins  "Hai friend how are you" and curser will be all at end of string
2 System.out,println()=> from these statement cursor will  go next line
3 System.out,printf(str,str)=>here its is one of method in console it functionality  will same as we uses in c programing printf()  here in System.out.printf(str,str); its has two argumants but its take only one  thats is first argument and prints that string and ignore the rest output=>"Hai friend how are you"

4 System.out,println()=> from these statement cursor will  go next line
5 System.out,format(str,str,str)=>here format method is also same printf method both are in printstream class both have same functionnality here  System.out.format(str,str,str) means its consist three string arguments but in that strings not include any format spectifiers like(%d,%c,%f) thats these strings are normal strings when normals strings are arguments its take only one  thats is first argument   and execute  and ignor the remaining arguments its result=>"Hai friend how are you";

total results is:
Hai friend how are you
Hai friend how are you
Hai friend how are you
option c:

Posted by Goutham Singarapu    2015-03-05 04:08:06


ANS IS C

Here different forms of print() method are used to display the string.

Posted by Mânïshå Mùlchåndânï    2015-03-05 16:05:21


This dose is now closed and the winners are Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Shashanka Mogaliraju. 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-03-06 02:03:49


© meritcampus 2019

All Rights Reserved.

Open In App