나는 루프를 만들려고했지만 "{"기호는 모든 인쇄 줄이 반복되는 것을 방지합니다. 사용자가 시퀀스 값을 입력 한 후 루프가 전체 첫 번째 문자열을 다시 표시하도록합니다.Loop - Do, while
import java.util.Scanner;
public class FtoC{
static Scanner cin = new Scanner (System.in);
public static void main(String[] args)
{
char userInput = ' ';
System.out.print("\nEnter " + "\"F\"" + " or " + "\"f\"" + " for Fahrenheit to Celsius"
+ "\nEnter " + "\"C\"" + " or " + "\"c\"" + " for Celsius to Fahrenheit"
+ "\nEnter something else to quit." +"\n");
userInput = cin.next().charAt(0);
if ((userInput == 'F') || (userInput =='f'))
{print("Enter a temp in Fahrenheit"
+"\n I will tell you temp in Celsius" +"\n");
far2cel();
}
else if ((userInput == 'C') || (userInput =='c')) {
print("Enter a temp in Celsius:"
+"\n I will tell you temp in fahrenheit" +"\n");
cel2far();
} else {
print("Terminating the program" + "\n");
}
}
private static void cel2far() {
Scanner input = new Scanner(System.in);
Double celsius = input.nextDouble();
print(celsius + " celsius is " + ((celsius * 9/5.0) + 32)
+ " Fahrenheit");
}
private static void far2cel() {
Scanner input = new Scanner(System.in);
Double Fahrenheit = input.nextDouble();
print(Fahrenheit + " Fahrenheit is " + ((Fahrenheit - 32) * (5/9.0))
+ " celsius");
}
private static void print(String string) {
System.out.print("\n" + string);
}
}
루프가 표시되지 않습니다. 시도한 루프 코드를 게시하도록 편집 할 수 있습니까? – ajb
코드에 루프가 하나도없는 do-while 루프에 대해 심각하게 묻고 있습니까? 이것을 시도하십시오 : https://www.google.com/search?q=java+do+while&oq=java+do+while – aliteralmind
" '기호는 모든 인쇄 라인이"어, 아니오. 오래된 튜토리얼을 읽을 시간. –