In: Computer Science
Create your own function in Java that accepts one input parameter and returns a float number. You decide the theme.
PROGRAM:
public class Division
{
// function returning a float int is the parameter, divded by 5 is the process
public float divideBy5(int num)
{
float out=(float)num/5;
return out;
}
// directly convert an int to float
public float convertIntTOFloat(int num)
{
float out=(float)num;
return out;
}
public static void main(String s[])
{
// object of the class
Division div=new Division();
//calling first function
System.out.println("The float num1 : "+div.divideBy5(33));
//calling second function
System.out.println("The float num2 : "+div.convertIntTOFloat(22));
}
}
OUTPUT:
The float num1 : 6.6
The float num2 : 22.0