This is the sixth solution to find the reverse of a float value using the StringBuffer (mutable) class.
import java.util.Scanner;
public class ReverseOfFloat {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner inpFloat= new Scanner(System.in);
//Input the float value
System.out.println("Enter a float value=");
float floatVal=inpFloat.nextFloat();
System.out.println("The float value is="+floatVal);
StringBuffer flt2Str=new StringBuffer(String.valueOf(floatVal));
String revFloatVal=flt2Str.reverse().toString();
System.out.println("The reverse value of decimal="+floatVal+" is="+Float.parseFloat(revFloatVal));
}
}
Output:
Enter a float value=
34.521
The float value is=34.521
The reverse value of decimal=34.521 is=125.43

Leave a comment