Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# printf into a printoutline for variable

bob sag
Greenhorn
Posts: 1
so i'm trying to input a printf to get these decimals to the second placement, but can't seem to figure it out! :\ any suggestions would be awesome! thanks
import java.util.Scanner;

public class testrun

{
public static void showKilometers(double meters)
{
double kilometers = meters / 15.00 * 0.001;
System.out.println(meters +" meters is " + kilometers + " kilometers per hour.");
}

public static void showMeters(double meters)
{
double metersps = meters / 15.00;
System.out.println(meters +" meters is " + metersps + " meters per second.");
double

System.out.printf("%5.2f %f",d,f); // prints 1.200000 1.200000
}

public static void showMiles(double meters)
{
double miles = meters / 15.00 * .000621371;
System.out.println(meters + "meters is " + miles + "miles per hour.");
}

public static void showFeet(double meters)
{
double feet = meters / 15.00 * 3.281;
System.out.println(meters +" meters is " + feet + " feet per second.");

}

public static void quitProgram()
{
System.out.println("Auf Wiedersehen!");
System.out.println(0);
}
{
System.out.println(" 1. Convert to kilometers ");
System.out.println(" 2. Convert to metersps ");
System.out.println(" 3. Convert to feet ");
System.out.println(" 4. Convert to miles");
System.out.println(" 5. Quit program ");
System.out.println(" ");
}
// print menu in 1 - 5
public static void main (String [] args)
{

double meters;
int choice;

Scanner keyboard = new Scanner (System.in);

System.out.println("Enter a distance in meters: ");
meters = keyboard.nextDouble();
choice = keyboard.nextInt();
switch(choice) //switch box
{
case 1: showKilometers(meters);
break;
case 2: showMeters(meters);
break;
case 3: showFeet(meters);
break;
case 4: showMiles(meters);
break;
case 5: quitProgram();
/* print f/n println ) %d____%f5.2__"int,sec);

*/
}
}
}

Aj Prieto
Ranch Hand
Posts: 75
Try: