import javax.swing.JOptionPane;
import java.text.NumberFormat;
public class Program4
{
public static void main(String[] args)
{
String input;
int won;
int lost;
double perc;
input = JOptionPane.showInputDialog("How many games were won");
won= Integer.parseInt(input);
input = JOptionPane.showInputDialog("How many games were lost");
lost = Integer.parseInt(input);
perc = won + lost / won;
System.out.println("The teams winning percentage is ");
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(3);
formatter.setMinimumFractionDigits(3);
System.out.println(formatter.format(perc));
System.exit(0);
}
}
The output comes out as something like 8.00 or 3.00, when it should be .800 and .300
My second program, I want it to output my age in years months and days:
import javax.swing.JOptionPane;
public class Program10
{
public static void main(String[] args)
{
final int MONTH = 30;
final int YEAR = 365;
String input;
int days;
int years;
int months;
input = JOptionPane.showInputDialog("Whats your age in days");
daays = Integer.parseInt(input);
years =
days = MONTH * years;
months = years / 12;
JOptionPane.showMessageDialog(null, years + " years " + months + " months and " + days + " days" );
}
}
Im not looking for the exact code for someone to give me, but some help or hints would be nice. I think the issue is that I have the correct code written, but I am missing or have incorrect formulas for each one. Could someone provide me with assistance. Thank you.
This post has been edited by smohd: 28 October 2011 - 02:31 PM
Reason for edit:: Title edited to be more descriptive

New Topic/Question
Reply



MultiQuote





|