import javax.swing.JOptionPane;
public class NewClass {
int i = 1;
public static void main(String[] args)
{
String output = "";
System.out.println("kilograms | pounds");
System.out.println("--------+-----------");
for ( i = 1; i <= 199; i ++)
{
// Every table line in between
System.out.printLn(“| “+i+” | “+i*2.2+” |”);
}
System.out.println(output);
} //end method
} // end class
这里出了什么问题,为什么我不能运行它?尝试显示从 1 到 199 的 KG 列表
最佳答案
你犯了一些错别字。这应该编译:
//Removed import because you aren't using it
public class NewClass {
public static void main(String[] args)
{
System.out.println("kilograms | pounds");
System.out.println("--------+-----------");
for (int i = 1; i <= 199; i ++)
// define i at this point because it's only used in this scope
{
System.out.println("| " + i + " | " + (2.2 * i) + " |");
// Use normal "
// you misspelled println
// put parenthesis around calculations
}
System.out.println("");
} //end method
} // end class
您应该考虑使用像 Eclipse 这样的 IDE 。它突出显示了上述错误。
关于java - 将公斤转换为磅程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21031822/