Page 327 - CITS - Computer Software Application -TT
P. 327

COMPUTER SOFTWARE APPLICATION - CITS




           Syntex
           System.out.println(parameter);
           // Java code to illustrate println()

           import java.io.*;
           class Demo {

               public static void main(String[] args)
               {

                   // using println()

                   // all are printed in the
                   // different line
                   System.out.println(“CSA WORLD “);
                   System.out.println(“CSA WORLD “);
                   System.out.println(“CSA WORLD “);

               }
           }
           Output:
           CSA WORLD
           CSA WORLD

           CSA WORLD


           •  printf(): This method in Java is reminiscent of the printf function in C. It is worth noting that while System.out.
              print() and System.out.println() accept a single argument, printf() can accept multiple arguments. Its primary
              purpose is to format the output in Java.
           public class PrintfExample {

               public static void main(String[] args) {
              String name = “ANSHU”;
              int age = 24;
              double salary = 50000.75;
              // Using printf to format output
                System.out.printf(“Name: %s%n”, name);

                System.out.printf(“Age: %d%n”, age);
                System.out.printf(“Salary: $%.2f%n”, salary);
                 }
            }

           Output
           Name: ANSHU
           Age: 34
           Salary: 50000.75



                                                           314

                              CITS : IT&ITES - Computer Software Application - Lesson 78 - 84
   322   323   324   325   326   327   328   329   330   331   332