不兼容的类型非常简单

时间:2014-09-24 10:00:43

标签: java types jcreator

我收到此错误:不兼容的类型
k0 =(i == 0 * 2);
......... ^

import java.util.Scanner; 公共课pers5 {

public static void main(String[] args) {

int k0,k1,k2,k3,k4,k5,k6,k7,k8,k9;
int produkt;

System.out.print("ange ett personnummer: ");
String indata = new Scanner(System.in).nextLine();
for (int i=0; i<10; i++){
    int nummer=indata.charAt(i) -48;
        System.out.print(indata.charAt(i)+ " ");
        System.out.println(indata.charAt(i));
//this code has lots of stuff between these two but its irrelevant.
k0= (i==0 * 2);
k1= (i==1 * 1);
k2= (i==2 * 2);
k3= (i==3 * 1);
k4= (i==4 * 2);
k5= (i==5 * 1);
k6= (i==6 * 2);
k7= (i==7 * 1);
k8= (i==8 * 2);
k9= (i==9 * 1);
produkt= k0+k1+k2+k3+k4+k5+k6+k7+k8+k9;

2 个答案:

答案 0 :(得分:1)

i==0以及后续调用返回一个布尔值,因此它不能分配给k0,因为它的类型为int

答案 1 :(得分:0)

你错过了这一点

k0 = (i == 0 * 2); // i == 0 * 2 resulting a boolean

因此k0必须是boolean。您可以使用boolean代替int