java - 将公斤转换为磅程序

标签 java

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/

相关文章:

java - 您如何告诉 Hibernate 您的实体类映射采用 JPA 1.0 语法?

Java - 使用递归的深度克隆数组;未知类型和未知深度

java - 如何在 for 循环中迭代文本并在 MapReduce() 中查找特定文本的计数

Java String 忽略大小写实现

java - 未在 Spring Controller 中执行验证

java - 具有 Java 版本依赖性的 RPM,yum 似乎认为它可以满足不同的版本

java - 线程重新运行run()方法

java - 在Java中,全局记录器和根记录器有什么区别?

java - Tomcat servlet 请求的资源不可用

java - AWSSDK V2 Java SES 发送电子邮件 - AmazonSimpleEmailService 无法解析