In Java, I want to scan user for formatString and inputDouble as follows:
Scanner scan = new Scanner(System.in);
System.out.println("Enter formating string and double to format:");
String formatString = scan.next();
Double inputDouble = scan.nextDouble();
But for now, let's say I only have
String formatString = "%.2f";
Double inputDouble = 42.424242;
I would to use the System.out.printf(); to format the inputDouble based on the formatString. Something like:
System.out.printf("Formated double: '%s'", formatString, inputDouble);
so something in form:
System.out.printf("Formated double: 'magicGoesHere'", formatString, inputDouble);
So in this particular case, I would like to see output:
Formated double: 42.42
Is it possible somehow? thanks
String.format(formatString, inputDouble), then use the resultingStringin yourSystem.out