Print in java



Print Function is used to print the elements. There are three common function used to print the statement in java.






Types



  1. System.out.print()
  2. System.out.println()
  3. System.out.printf()







1. System.out.print()




System.out.print() this method used for print the given elements.



Example-1
public class Main
{
      public static void main(String[] args) 
      {

           System.out.print("mycrazycoding");

      }
}


Output



mycrazycoding







Example-2
public class Main
{
      public static void main(String[] args) 
      {

            int a = 5;

            System.out.print(a);

      }
}


Output



5







Example-3
public class Main
{
      public static void main(String[] args) 
      {

            String s = "mycrazycoding";

            int year = 2020; 

            System.out.print("site: "+s+" year:"+year);

      }
}


Output



site: mycrazycoding year:2020








2. System.out.println()




System.out.println() method used for print the given statement and next statement should be next line. System.out.println("coding") = System.out.print("coding\n"). The both statements are same.





Example
public class Main
{
     public static void main(String[] args) 
     {

          System.out.println("mycrazycoding");

          System.out.println("mycrazycoding");

     }
}


Output



mycrazycoding
mycrazycoding







3. System.out.printf()




System.out.printf() is used to print the given statement in a format order.




Example
public class Main
{
     public static void main(String[] args) 
     {

         int year = 2020;

         String site = "mycrazycoding";

         System.out.printf("Site:%s and Year:%d",site,year);

     }
}


Output



Site:mycrazycoding and Year:2020