So what I'm aiming for here is to take the user's input as float and write code to split up that input into individual digits and use an array.
How would I go about doing this?
Here is what my code looks like currently:
import java.util.Scanner;
public class Asn8
{
public static void main(String args[])
{
Scanner kb = new Scanner(System.in);
String s1;
System.out.println("Please enter the name on the check (First Last) : ");
s1 = kb.nextLine();
System.out.println("Please enter the amount for the check (as a float) : ");
float f1 = kb.nextFloat();
if(f1 < 0)
System.out.println("Invalid amount : " + f1);
System.out.println("\n------------------------------------------------------");
System.out.println("\nPay to : " + s1 + "\t\t\t\t$" + f1);
}
}
Here is the final output that was provided:
Please enter the name on the check (First Last): Maya Tolappa
Please enter the amount for the check (as a float): 123.45
---------------------------
Pay to : Maya Tolappa $123.45
one hundred twenty three dollars and 45 cents
The 123.45 which is input as a float is taken and displayed as "one hundred twenty three dollars and 45 cents"
It isn't supposed to just work for 123.45 but all floats.
All feedback is much appreciated,
- Aepex