Ask Experts Questions for FREE Help !
Ask
    overlord2042's Avatar
    overlord2042 Posts: 1, Reputation: 1
    New Member
     
    #1

    Apr 20, 2017, 04:21 AM
    ZİG ZAG matrix
    i would like some one expert to see my codes and tell my if there is another way to write this codes or can make any changes that leads to the same results




    import java.util.Scanner;
    public class answer {
    public static void main(String args[]) {


    Scanner in = new Scanner(System.in);

    System.out.print("enter value: ");

    int value = in.nextInt();
    int num=0;


    int i=0;
    int j=0;
    boolean upperCorner = false;
    boolean lowerCorner = true;
    int matrix[][]=new int[value][value];
    while (num!=value*value){
    matrix[i][j]=num++;



    if ( (i == 0 && j != value -1 ) && lowerCorner ){
    j++;
    upperCorner = true;
    lowerCorner = false;
    }
    else if ( (j == 0 && i != value -1 ) && upperCorner ){
    i++;
    lowerCorner = true;
    upperCorner = false;
    }
    else if ( (j == value -1 ) && lowerCorner ){
    i++;
    lowerCorner = false;
    upperCorner = true;
    }
    else if ( (i == value -1 ) && upperCorner ){
    j++;
    lowerCorner = true;
    upperCorner = false;
    }
    else if (upperCorner ) {
    j--;i++;
    }
    else if ( lowerCorner ) {
    i--;j++;
    }
    }


    for (i=0;i<value;i++){
    for (j=0;j<value;j++){
    System.out.printf("%5d",matrix[i][j]);
    }
    System.out.printf("\n");
    }
    }
    }

Check out some similar questions!

What does it mean to see zig zag flashes in eyes [ 1 Answers ]

What are the possibilities of an eye problem whereby you see zig zag flashes in your eyes?

7 jewel zig zag morse [ 0 Answers ]

Please help my mom gave me a Morse 7 Jewel zig zag made in Japan for Montgomery Ward model # URR 988A serial # 55X. Does anyone know the possible age and worth of the machine? I've checked the internet numerous times. Would also like to know if its possible to find parts and manuals.

7 jewel zig zag morse [ 0 Answers ]

Please help my mom gave me a Morse 7 Jewel zig zag made in Japan for Montgomery Ward model # URR 988A serial # 55X

Singer zig zag model 413 [ 3 Answers ]

Can the Singer zigzag 413 machine do a blind hem? (not a blind stich but a blind hem) Thank you! Christine


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.