Regexs

Regexs

Sir/Madam,

please tell me the meaning of the following code

import java.io.*; import java.util.*; class Demo{
public static void main(String args[]){
double d=1000000.1232323d; System.out.println(d);
System.out.printf("%,.2f",d); } }

I can't understand this line " System.out.printf("%,.2f",d);"

View Answers

May 21, 2013 at 6:51 PM

hi friend,

There are various of topics to be discussed lets see one by one.

  1. import : import is a keyword in Java which is used to declare a class. Once you have declare the class using import keyword you can use the corresponding class any number of times in the code below the import statement without specifying the package name of that class. import statement can be used in two ways : (i) import fullySpecifiedPackage.ClassName; and (ii) import package.*; The firs way of import statement declares the particular Class whereas, in the other way of import statement declares the whole class of the corresponding package.

  2. class : class is a Java keyword which is used to declare a class in Java.

  3. public static void main(String args]) : This is predefined method in Java from where your program may starts to execute. To know more in detail please go through the following link [Understanding public static void main function

  4. double d=1000000.1232323d : This is a way of declaring constant of data type double.

  5. System.out.println() : System is a class which is used to directly access System's standard input/output and error output streams, out is a static member field of System class which is a PrintStream type, println/print() is overloaded method which is used to print the argument at the standard console.

  6. System.out.printf() : We have been already discussed about System and out. Now we will discuss about printf() method. printf() method is used to print the argument at the standard console in a specific format. In your code the constant value will be formatted as 1,000,000.12, in the printf() method .2f specifies how many numbers will be displayed after the decimal point.

Thanks.









Related Tutorials/Questions & Answers:
Regexs
WRITE a simple JSP
(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec(window.location.href); if( results == null
Advertisements
jsp
(name){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var

Ads