Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printf into a printoutline for variable

 
bob sag
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
public static void showMenu()
{
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();
showMenu();
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
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:



Also, please UseCodeTags.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50240
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aj Prieto wrote: . . . Also, please UseCodeTags.
I would have added code tags, but the code was not indented.

Welcome to the Ranch bob sag. You are much more likely to get an answer if your code is easy to read, which your current post is not. Please have a look here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic