this
is the program illustrates how we can print the output as required format it is
achieved by the Number Format class they may be instance or abstract class for
this type of classes we can’t create Objects by new operator but some static methods exist to use that they
are called as Factory Methods by using that Factory Methods we can behave a
variable as Number Format class object So that all methods provide by that
class we can make available to our program
import
java.lang.*;
import
java.io.*;
import
java.text.*;
class number
{
public
static void main(String args[]) throws
Exception
{
double
d=1.24789316;
System.out.println("before
the value of "+d);
NumberFormat
nf=NumberFormat.getNumberInstance();
DataInputStream
k=new DataInputStream(System.in);
System.out.println("\n
enter the howmany numbers");
int
fd=Integer.parseInt(k.readLine());
nf.setMaximumFractionDigits(fd);
nf.setMinimumIntegerDigits(4);
String
x=nf.format(d);
System.out.println("\n
the output after format is\t\t"+x);
}
}
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి