View Single Post
  #2 (permalink)  
Old 08-06-2007, 07:52 AM
hardwired hardwired is online now
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.util.Scanner; import javax.swing.JOptionPane; public class Converter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String choice; do { System.out.println("enter fahrenheit"); int f = Integer.parseInt(scanner.nextLine()); int celsius = convert(f); String s = String.valueOf(f) + " = " + celsius + " celsius"; JOptionPane.showMessageDialog(null, s, "Converter", JOptionPane.PLAIN_MESSAGE); System.out.println("More? \"y\" or any key"); choice = scanner.nextLine(); } while(choice.equals("y")); scanner.close(); } private static int convert(int fahrenheit) { return 5*(fahrenheit - 32)/9; } }
Reply With Quote