转换公斤到磅程序

转换公斤到磅程序

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/

10-11 22:29