Java 减去两个长值

Java 减去两个长值,java,subtraction,Java,Subtraction,为什么在运行下面的代码时会出现错误?我怎样才能解决这个问题?我想System.out.print(你好) 属性声明和init应该在类中: public class HelloWorld{ Long hello = 43; Long hi = 3523; 如果您没有得到正确的结果,则不在外: 您的Long格式不正确,应该是这样的: Long hello = 43L; Long hi = 3523L; public class HelloWorld { static

为什么在运行下面的代码时会出现错误?我怎样才能解决这个问题?我想
System.out.print(你好)


属性声明和init应该在类中:

public class HelloWorld{
    Long hello = 43;
    Long hi = 3523;
如果您没有得到正确的结果,则不在外:

您的Long格式不正确,应该是这样的:

  Long hello = 43L;
  Long hi = 3523L;
public class HelloWorld
{
  static Long hello = 43L;
  static Long hi = 3523L;
  public static void main(String[] args)
  {
    System.out.print(hi-hello);
  }
}
当您在静态方法中调用属性时,应该将它们设置为静态,因此您的程序应该如下所示:

  Long hello = 43L;
  Long hi = 3523L;
public class HelloWorld
{
  static Long hello = 43L;
  static Long hi = 3523L;
  public static void main(String[] args)
  {
    System.out.print(hi-hello);
  }
}
这将打印:

3480
注意

正如@EJP在评论中所说:

当一个数字太大而不能用int表示时,它必须是 通过添加L显式声明为long:

long n = 9876543210L;

由于hilow被声明为LONG对象,因此必须通过在末尾添加L或使用LONG类将它们声明为literal

public class HelloWorld {
     public static void main(String[] args) {
        Long hello = 43L;
        Long hi = 3523L;
        System.out.print(hi-hello);
     }
}

Long不使用正常运算符,如+-,而是需要使用
Long.sum(Long l1,l2)


我不确定是否还有其他方法可以做到这一点,但这就是我所使用的。

打印需要较长的参数吗?@huseyintugrulbuyukisik我不知道,如果您有internet并且使用eclipse,您应该启用文档提要。然后检查警告和错误请确保OP有互联网:)@ZhongYu我觉得自己像个白痴bwhahahahaha。(也许我现在是)我想减去hi,helloi不想输出“hi hello”!输出3480基本上这里不需要L后缀。@EJP我使用了他在问题中所说的,所以他使用了
Long
L
not
Long
好,检查我的答案now@Me123这不是正确的答案。L后缀在这些小值上是不必要的。我匆忙否决了这个答案,但它是正确的答案。我想还原一下。有什么建议吗?