File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes printf into a printoutline for variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "printf into a printoutline for variable" Watch "printf into a printoutline for variable" New topic
Author

printf into a printoutline for variable

bob sag
Greenhorn

Joined: Jan 14, 2013
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);
}
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

Joined: Sep 28, 2012
Posts: 72

Try:



Also, please UseCodeTags.


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37879
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printf into a printoutline for variable
 
Similar Threads
While and Do-While Question
Two scanner FileReader
' + ' Operator problem
LengthConverter
Can't understand this tricky for loop question