my output output a large number of newlines to force the old board off the screen. how to stored the memory from first output if the first input is true but the second input not true. how to display to new line screen?
import java.util.*;
public class ModifiedMemory
{
public static void main (String[]args)
{
int cards [][]= new int[4][4];
fillboard(cards);
shuffle(cards);
shownum(cards);
displayboard(cards);
play(cards);
//reveal(cards);
//match(cards);
}//main
public static void reveal (int cards[][])
{
int r1, c1, r2, c2, i;
System.out.println("Please insert the first card row and column seperated space ");
Scanner input = new Scanner(System.in);
r1 = input.nextInt();
c1 = input.nextInt();
System.out.println("Please insert the second card row and column seperated space ");
r2 = input.nextInt();
c2 = input.nextInt();
//fix
r1--;
c1--;
r2--;
c2--;
{//reveal
System.out.print(" 1 2 3 4\n");
System.out.print(" ");
for (i=0; i<=8; i++)
{
System.out.print("-");
}
System.out.println();
for (int r=0; r<4; r++)
{
System.out.print(r+1);
System.out.print(" | ");
for (int c=0; c<4; c++)
{
if ((r==r1)&&(c==c1))
{
System.out.print(cards[r][c]+" ");
}
else if((r==r2)&&(c==c2))
{
System.out.print(cards[r][c]+" ");
}
else
{
System.out.print("* ");
}
}
System.out.println();
}
}
}//reveal
public static void fillboard (int cards[][])
{
int i = 0;
{
for (int r=0; r<4; r++)
{
if (r%2==0)
{
i=0;
}
for (int c=0; c<4; c++)
{
i++;
cards[r][c]=i;
}
}
}
}//fill
public static void displayboard (int x[][])
{//display board
int i = 0;
System.out.println();
System.out.println(" 1 2 3 4");
System.out.print(" ");
for ( i=0; i<=8; i++)
{
System.out.print("-");
}
System.out.println();
for (int r=0; r<4; r++)
{
System.out.print((r+1) +" | ");
for (int c=0; c<4; c++)
{
System.out.print("* ");
}
System.out.println();
}
System.out.println();
}//display
public static void shownum(int cards[][])
{
for (int r=0;r<4;r++)//show num
{
for (int c=0; c<4;c++)
{
System.out.print(" "+ cards[r][c] );
}
System.out.println();
}
}// show num
public static void shuffle(int cards[][])
{
//shuffle
Random rand = new Random();
int i=0, j=0, temp;
for (int r=0;r<100;r++)
{
for (int c=0; c<100;c++)
{
i=rand.nextInt(4);
j=rand.nextInt(4);
temp=cards[i][j];
cards[i][j]=cards[j][i];
cards[j][i]=temp;
}
}
}//shuffle
public static void play(int[][] cards)
{
int r1 = 0,c1 = 0,r2 = 0,c2 = 0, i, j,c,r;
int more = 0;
do
{
for (r=0;r<4;r++)
for (c=0;c<4;c++)
{
System.out.println("Please insert the first card row and column seperated space ");
Scanner input = new Scanner(System.in);
r1 = input.nextInt();
c1 = input.nextInt();
System.out.println("Please insert the second card row and column seperated space ");
r2 = input.nextInt();
c2 = input.nextInt();
r1--;
c1--;
r2--;
c2--;
//fix
{
System.out.print(" 1 2 3 4\n");
System.out.print(" ");
for (i=0; i<=8; i++)
{
System.out.print("-");
}
System.out.println();
{
for (r=0; r<4; r++)
{
System.out.print(r+1);
System.out.print(" | ");
for (c=0; c<4; c++)
{
if ((r==r1)&&(c==c1))
{
System.out.print(cards[r][c]+" ");
}
else if((r==r2)&&(c==c2))
{
System.out.print(cards[r][c]+" ");
}
else
{
System.out.print("* ");
}
}
System.out.println();
}
}
}
if(r1>4 || c1>4 || r2>4 || c2>4)
{
System.out.println("Invalid coordinate!");
}
else
{if (cards[r1][c1]==cards[r2][c2])
{
System.out.println("Good! it is match");
System.out.print("Press 1 to insert other number: ");
more = input.nextInt();
System.out.println();
}
else
{ //this pushes the next board onto a blank screen
for (int b=0; b<=20; b++)
//how to calling the memory in here?
System.out.println();
//repeat
System.out.println("Not Match");
System.out.print("Continue? 1 for yes:");
more = input.nextInt();
System.out.println();
}
}
//reveal
}
}while(more==1);
System.out.print("Find more number");
}
public static void Memory(int[][] cards)
{
play(cards);
}
}