Convert Java
float Primitive Value to Float Object
public class
JavafloatToFloatExample
{
public static void
main(String[] args)
{
float f = 10.56f;
Float fObj = new Float(f);
System.out.println(fObj);
}
}
Java Float
Compare
public class
JavaFloatCompareExample
{
public static void
main(String[] args)
{
float f1 = 5.35f;
float f2 = 5.34f;
int i1 =
Float.compare(f1,f2);
if(i1 > 0)
{
System.out.println("First
is grater");
}
else if(i1 < 0)
{
System.out.println("Second
is grater");
}
else
{
System.out.println("Both
are equal");
}
Float fObj1 = new
Float("5.35");
Float fObj2 = new
Float("5.34");
int i2 =
fObj1.compareTo(fObj2);
if(i2 > 0)
{
System.out.println("First
is grater");
}
else if(i2 < 0)
{
System.out.println("Second
is grater");
}
Else
{
System.out.println("Both
are equal");
}
}
}
Java Float
Wrapper Class
public class
JavaFloatExample
{
public static void
main(String[] args)
{
float f = 10.10f;
Float fObj1 = new
Float(f);
System.out.println(fObj1);
double d = 10.10;
Float fObj2 = new
Float(d);
System.out.println(fObj2);
Float fObj3 = new
Float("25.34");
System.out.println(fObj3);
}
}
Java Float is
Infinite Method
public class
JavaFloatIsInfiniteExample
{
public static void
main(String[] args)
{
float f = (float) 1/0;
boolean b1 =
Float.isInfinite(f);
System.out.println(b1);
Float fObj = new Float(f);
boolean b2 =
fObj.isInfinite();
System.out.println(b2);
}
}
Java Float is Na
N Method
public class
JavaFloatIsNaNExample
{
public static void
main(String[] args)
{
float f = (float)
Math.sqrt(-10);
boolean b1 =
Float.isNaN(f);
System.out.println(b1);
Float fObj = new Float(f);
boolean b2 = fObj.isNaN();
System.out.println(b2);
}
}
Convert Integer
to Java String object
public class
IntegerToStringExample
{
public static void
main(String[] args)
{
Integer intObj = new
Integer(10);
String str =
intObj.toString();
System.out.println("Integer
converted to String as " + str);
}
}
No comments:
Post a Comment