我有一个代码,它将使用用户输入为我提供数组中某些点的坐标。如果数组中的数字不存在,我将添加什么代码以使代码输出显示找不到地址?我很确定我需要一个 else 语句,但我无法让它工作。这是我现在拥有的代码。
import java.util.Scanner;
public class LabActivityArray
{
public static void main (String[] args)
{
Scanner scanner = new Scanner (System.in);
int rows;
int columns;
int check1,check2;
System.out.println("Enter number of rows: ");
rows = scanner.nextInt();
System.out.println ("Now enter the number of columns: ");
columns = scanner.nextInt();
int[][] array = new int[rows][columns];
System.out.println("Enter the number to start the array: ");
int value = scanner.nextInt();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
array[i][j]=value++;
System.out.print(array[i][j] + " " );
}
System.out.println();
}
System.out.println("Please give one integer value to be checked in the array: ");
check1 = scanner.nextInt();
System.out.println ("Please give a second integer value to be checked in the array: ");
check2 = scanner.nextInt();
for ( int i = 0; i < rows; ++i )
{
for ( int j = 0; j < columns; ++j )
{
if ( array[i][j] == check1 )
{
System.out.print(array[i][j] + " is located at address array[" + i + "," + j + "]");
}
if ( array[i][j] == check2 )
{
System.out.print("\n" + array[i][j] + " is located at address array[" + i + "," + j + "]");
System.out.println();
}
}
}
}
}