Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I JUST NEED HELP ON THE LAST PART. I\'M GETTING THE DIAGONAL BUT I NEED THE REVE

ID: 3551688 • Letter: I

Question

I JUST NEED HELP ON THE LAST PART. I'M GETTING THE DIAGONAL BUT I NEED THE REVERSE DIAGONAL!





import java.util.Scanner;

public class AsciiArt

{

public static void main (String[] args)

{

Scanner myscan= new Scanner(System.in);

int n; //Declare all the integers

int i=0; //Declare all the integers

int j; //Declare all the integers

int k; //Declare all the integers

System.out.println("Choose one of the following patterns by typing the corresponding number: ");

System.out.println("1) Grid");

System.out.println("2) Checker Board");

System.out.println("3) Reverse Diagonal");


n=myscan.nextInt(); //If user inputs incorrect number, Error message shows up

if (n>3)

{

System.out.println("Error.");

System.exit(0);


}


System.out.println("Input a size (must be larger than 1):");


k=myscan.nextInt(); //If user inputs incorrect number, Error shows up

if (k<2)

{

System.out.println("Error.");

System.exit(0);

}

System.out.println();


if (n==1){ //First option

for (i = 0; i < k; i++)

{

System.out.print(i + " ");

for ( j = 0; j < k; j++)

{

System.out.print("*");

}

System.out.println();

}

}

if (n==2){ //Second Option

for (i = 0; i < k; i++)

{

System.out.print(i + " ");

for ( j = 0; j < k; j++)

{

if ( (i % 2) == (j % 2) )

System.out.print("*");

else

System.out.print(" ");

}

System.out.println();

}

}

if (n==3){ //Third Option

for (i = 0; i < k; i++) {

System.out.print(i + " ");

for ( j = 0; j < k; j++) {

if ((i) == (j))

System.out.print("*");

else

System.out.print(" ");

}

System.out.println();

}

}

}

}


Explanation / Answer

/* OUTPUT
Choose one of the following patterns by typing the corresponding number:
1) Grid
2) Checker Board
3) Reverse Diagonal
Input a size (must be larger than 1):

0      *
1     *
2    *
3   *  
4 *   
5 *    
*/

import java.util.Scanner;
public class AsciiArt
{
public static void main (String[] args)
{
Scanner myscan= new Scanner(System.in);
int n; //Declare all the integers
int i=0; //Declare all the integers
int j; //Declare all the integers
int k; //Declare all the integers
System.out.println("Choose one of the following patterns by typing the corresponding number: ");
System.out.println("1) Grid");
System.out.println("2) Checker Board");
System.out.println("3) Reverse Diagonal");
n=myscan.nextInt(); //If user inputs incorrect number, Error message shows up
if (n>3)
{
System.out.println("Error.");
System.exit(0);
}
System.out.println("Input a size (must be larger than 1):");
k=myscan.nextInt(); //If user inputs incorrect number, Error shows up
if (k<2)
{
System.out.println("Error.");
System.exit(0);
}
System.out.println();
if (n==1){ //First option
for (i = 0; i < k; i++)
{
System.out.print(i + " ");
    for ( j = 0; j < k; j++)
    {
        System.out.print("*");
    }
    System.out.println();
}
}
if (n==2){ //Second Option
for (i = 0; i < k; i++)
{
System.out.print(i + " ");
    for ( j = 0; j < k; j++)
    {
    if ( (i % 2) == (j % 2) )
            System.out.print("*");
         else
            System.out.print(" ");
}
    System.out.println();
}
}
if (n==3){ //Third Option
for (i = 0; i < k; i++) {
System.out.print(i + " ");
    for ( j = 0; j < k; j++) {
if ((i) == (k-1-j))
            System.out.print("*");
         else
            System.out.print(" ");
}
    System.out.println();
}
}
}
}