Difference between Print() and Println() Methods ?

Difference between Print() and Println() Methods ?


Print() method will displaying given value in the same line and places cursor in the same so that the next coming value  will be also displayed in the same line .


where as println method will display the  value in same line the moves cursor to next line . so that the next displaying value will be printed in the next line .

the "ln" property is applicable in next displaying values but not on current displaying value .

hence we must choose either print() or println() method depending on the next  value printing line .

if we want print both current value  and next value in the same line , we must  display current value by using print () method .

if we want to print current value and next value in different lines we must display current value by using println () method .

Question-Develop a program to display the below 5 statements in 3 line as shown in the below pattern .

input                  Output
                                              
A                        A, B
B
C                       C, D
D                        E
E      

Program-

New javaprogram.java

Class javaprogram{
      
public static void args(String[]args){
        System..out.print("A");
         System..out.println("B");
          System.out.print("C");
            System.out.println("D");
               System.out.print("E");
      }
}                     

Share this

Related Posts

Previous
Next Post »

Recent