Home >>Java Programs >Printing the format text with printf in Java
In this example, we will see a Java program in which we will print the formatted text with printf.
In Java printf is the method of System.out class. It is System.out.printf method where 'f' stands for formatted.
Program:
public class Main
{
public static void main(String []args)
{
int a,b,sum;
float average;
a=100; b=200;
sum=a+b;
average=sum/2;
System.out.printf("Sum is= %d\n",sum);
System.out.printf("Average is= %f\n",average);
}
}