• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

printf into a printoutline for variable  RSS feed

 
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);


*/
}
}
}
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:



Also, please UseCodeTags.
 
Marshal
Posts: 64494
225
  • 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.
 
Just the other day, I was thinking ... about this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!