java变量错误_Java错误消息“无法解析为变量”?

好吧所以我对

java有点新意,我正在尝试创建一个类,它可以要求用户输入一个12位长的upc代码,检查以确保它是一个有效的代码,然后显示它是否是或不.我当前的程序有很多错误,我似乎无法弄明白.这是我到目前为止的代码:

public class Upc {

private long upc;

public Upc(long upcs) {

upc = upcs;

}

public long getUpc() {

int m = (n2 + n4 + n6 + n8 + n10);

long n = (n1 + n3 + n5 + n7 + n9 + n11);

long r = (10 - (m + 3 * n) % 10);

long n12 = (int) (upc % 10);

upc /= 10;

long n11 = (int) (upc % 10);

upc /= 10;

long n10 = (int) (upc % 10);

upc /= 10;

long n9 = (int) (upc % 10);

upc /= 10;

long n8 = (int) (upc % 10);

upc /= 10;

long n7 = (int) (upc % 10);

upc /= 10;

long n6 = (int) (upc % 10);

upc /= 10;

long n5 = (int) (upc % 10);

upc /= 10;

long n4 = (int) (upc % 10);

upc /= 10;

long n3 = (int) (upc % 10);

upc /= 10;

long n2 = (int) (upc % 10);

upc /= 10;

long n1 = (int) (upc % 10);

if (r == n12) {

return (upc + " is a feasible UPC code");

} else {

return (upc + " is an invalid UPC code");

}

}

}

我的错误如下:

13 errors found:

File: C:\Users\Andrew\Downloads\Upc.java [line: 10]

Error: n2 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 10]

Error: n4 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 10]

Error: n6 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 10]

Error: n8 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 10]

Error: n10 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n1 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n3 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n5 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n7 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n9 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 11]

Error: n11 cannot be resolved to a variable

File: C:\Users\Andrew\Downloads\Upc.java [line: 39]

Error: Type mismatch: cannot convert from java.lang.String to long

File: C:\Users\Andrew\Downloads\Upc.java [line: 42]

Error: Type mismatch: cannot convert from java.lang.String to long

我觉得修一两件事会消除很多这个,有人能帮帮我吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值