package masivi;
import java.util.Scanner;
public class Masivi {
public static void main (String args[]){
int atzimes[][]={{50,60,55,67,73},
{62,65,71,70,81},
{72,66,77,80,69}};
int a = 0;
int b = 0;
int Y = 0;
int D = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Ievadiet skaitli kuru velaties parbaudit:");
int x = scan.nextInt();
while (Y<16){
if (atzimes[a][b] == x) System.out.println("Skaitlis "+x+" atrodas saja masiva.");
Y=Y+1;
if (atzimes[a][b] == x) break;
b=b+1;
if (b==4) a=a+1;
if (b==4) b=0;
if (a==2) ;
}
if (atzimes[a][b] == x) System.out.println("" );
else System.out.println("Skaitlis "+x+" neatrodas masiva." );
}
}
当我检查最后一个值(69)时,它超出了界限,我不知道为什么。我试过改变循环结束的值,但它没有帮助我目前没有想法。它要求 x 的值并检查是否在数组中。