我試圖重複打印出一定的打印量「轉換#1」 的數轉換,但上升的基礎上的用戶輸入,因此如果用戶輸入他們想要3個不同轉換這將是:重複用戶輸入
轉換#1
代碼....
轉換#2
代碼...
轉換#3
代碼...
這是我的代碼:
import java.util.Scanner;
import java.text.DecimalFormat;
public class TempConverter {
public static void main(String[] args){
DecimalFormat df = new DecimalFormat("#,###.0");
System.out.println("Temperature Converter");
System.out.println("---------------------");
Scanner input = new Scanner(System.in);
//this is the conversion promt
System.out.print("How many conversions would you like to make: ");
int conversions=input.nextInt();
for(int i = 0; i < conversions; i++);
System.out.println("Conversion # " + i++);
System.out.println ("To convert from celsius to fahrenheit type 1 ");
System.out.print ("To convert from fahrenheit to celsius type 2: ");
int choice=input.nextInt();
System.out.print ("Enter temperature: ");
double temp=input.nextDouble();
double result=tempChanger(choice,temp);
if (choice == 1)
System.out.println ("The conversion of "+temp+" from celcius to fahrenheit is "+df.format(result));
else if (choice == 2)
System.out.println ("The conversion of "+temp+" from fahrenheit to celcius is "+df.format(result));
else
System.out.println ("Not a valid choice, try agiain");
}
public static double tempChanger(int choice, double temp)
{
double converted=0.0;
if (choice == 1)
converted=9.0/5.0*temp+32;
else
converted=5.0/9.0*(temp -32);
return converted;
}
}
你印刷的要求和代碼,但沒有解釋 - 什麼是不工作?你不明白什麼?你的具體問題是什麼? –
看起來像你的{}後您的for循環失蹤。 –
它會問有多少轉換號碼的用戶,但是當我運行的代碼,它只是忽略轉換問題。 – mvanderk10