DISPLAY THE RESULT ON THE CONSOLE


Don’t worry about all the word about the keywords and programming about , ‘class’ , ‘System.out.print’. You just make a clear idea that in how many ways we can print the solution on the screen . 
  • In order to display the result on the console we need to make use of  “ println() ” method
  • The println() method is the pre-defined method of printstream class which is turn belongs to the java.io  package .
  • The println() method will produce the result on the screen in the new line
  • It is an overloaded method of printstream class ( overloading is the process of defining more than one method with the same name but for different purposes ) .
  • println() method will take only one argument .
  • the overloaded methods of println() method is

println(byte); println(short); println(float); println(char); println(boolean); println(double); println(int); println(string) etc

These all the methods are belongs to the printstream class.

when you are writing the Java program in any of the Java program editor that is editplus or netbeans the red coloured are the classes and the blue coloured are the keywords.

program on println() method :

class Sample 

{

  public static void main(String args[])

  {

    System.out.println(“welcome”);

    System.out.println(“c”);

    System.out.println(“10+20”);

    System.out.println(“sai”+” baba”);

    System.out.println(10+” “+20);

 }

}

output :

NOTE : IN JAVA THE + IS THE POLYMORPHIC BEHAVIOUR IN NATURE OPERATOR. THE BEHAVIOUR OF THE OPERATOR IS GETTING VARY AT DIFFERENT INSTANCES.

print() :

  • It is also a pre-defined method of PritnStream class oj java.io package , but it produces the result in the same line .
  • java.io package  —->   PritntStream class —–> print();

printf() :

  • It is also a pre-defined method of PrintStream class of java.io package which is available in java6 and higher versions . It works exactly same like the printf() function in your “c-lang”

printf() program :

class PrintfEx1

{

  public static void main(String args[])

  {

    int sno=100;

    String sname=”willsmith”;

    float avg=99.99f; // f- because the value may chabge into                         double      , thats why  we are putting f 

    System.out.printf(“\n sno is %d \n sname is %s %n avg is                 %f”,sno,sname,avg);

  }

}


output :

2 responses

  1. pls sir…make a blog.. which can teach ..how to create a website…easily..

    1. surely but i should collect some time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: