【发布时间】:2015-09-17 00:41:39
【问题描述】:
if 语句在第一次之后被忽略
import java.util.Scanner;
public class practiceProgram3SecondTry
{
static Scanner scan = new Scanner(System.in);
public static void main (String[] args)
{
System.out.println("This program is intended to convert a temperature from Celcius to Fahrenheit, and other way around.");
int infiniteLoop = 0;
int oneLimitLoop = 0;
for(int x = 0 ; x < 1 ; x--)
{
//**System.out.println(infiniteLoop); // loop tester
System.out.println("Is it is Celcius, or Fahrenheit");
System.out.println("Please enter C/c frr celcius, or F/f for Fahrenheit");
String tempType = scan.nextLine();
scan.nextLine();
System.out.println("You may now enter the desisred temperature you would like to convert");
int tempNumber = scan.nextInt();
if (tempType.equalsIgnoreCase("c"))
{
int celcius = tempNumber;
int celciuscConverter = (9*(celcius)/5)+32;
System.out.println(celciuscConverter);
}
else if (tempType.equalsIgnoreCase("f"))
{
int fahrenheit = tempNumber;
int farenheitConverter = 5 * (fahrenheit-32)/9;
System.out.println(farenheitConverter);
}
}
}
}
【问题讨论】:
-
另外,这应该是一个无限循环,我想一直询问用户温度变化,情况是,它没有经过第一个循环之后的if语句。跨度>
标签: java if-statement for-loop skip