-3

I am just learning java and while completing an assignment i ran into a problem. I need to use the for loop but I'm unsure of the proper coding. I was able to compile my code to get the output for the 1st challenge but i am unable to do so for the remaining challenges. Any suggestions/tips are greatly appreciated.

/Your instructor is in a bind.  His place of work has instituted a new 
//technology project that will require remote access verification. 
//In addition to his user name and password, he will have a “challenge” 
//to each sign-on. That challenge will require that he input a number or 
//letter depending on what the security application asks him.
//But your instructor is lazy. He wants an application that will 
//tell him what those appropriate numbers are without him having to 
//look them up each time.  He understands that this will help foil 
//remote hackers, but he does not want to be stuck carrying around a piece of paper all the time.

//Write your instructor a program that gives him the three characters asked for.  The matrix to use is:
//A B C D E F G H I J 
//1 3 N 1 M 4 R X 5 F N
//2 N V T 5 K Q F M 3 P
//3 9 K 1 Y R 4 V T F 3
//4 3 3 9 V 4 Y R T N N
//5 3 1 1 3 2 9 X P N P

//A challenge of A1:B2:C3 would yield 3 V 1.
//A challenge of G4:D2:J3 would yield R 5 3.

// 1. Create a place to accept input
            //  ---- create a scanner class
            // 2. ask for input  
            String  input = "a1";


            // 3. Take the first character from the challenge
            //      (like "D2" would "D" and find its analogous int array value)

            int i1 = Util.findFirstValue(input);
            System.out.println(i1);

            // 4.Take the second character from the challenge (like "D2"
            //      would be "2") and find its analogous int array value
            //      Hint: always one less than the value entered.
            int i2 = Util.findSecondValue(input);
            System.out.println(i2);

            // 5. inquire with the array with the challenge values to get the desired value

            System.out.println(Util.findArrayValue(i1, i2));

            // 6. display the value 
            // 7. repeat twice more steps 2 through 6
        }


        {   
        for (int row =1; row<9;row ++) {
        for (int column =2; column <5;column ++) {
3
  • What's your question? Commented Jul 25, 2014 at 4:23
  • a lot of lost brackets Commented Jul 25, 2014 at 4:24
  • You really don't know how to ask a question mate !! Commented Jul 25, 2014 at 4:34

2 Answers 2

0

For looping through multi dimensional arrays it must like this

for(int i=0; i<multiarray[i].length; i++) {
multiarray[i][k]; //do something with it!
}

You can find heree about iterating multi dimensiona array in java.

Sign up to request clarification or add additional context in comments.

Comments

0

Think of a 2D array like a table. The first for loop to get a row from that table, then the next for loop gets a certain element from that row (column).

1, 2, 3
4, 5, 6     -->        4, 5, 6       -->         6
7, 8, 9   array[1]               array[1][2]    

So basically. The first loop gets the basic array within the 2D array, the next gets that exact value in that basic array.

Code:

int[][] A = { {1,2,3},
              {4,5,6},
              {7,8,9} };

for(int i = 0; A.length>i; i++) {
    for(int j = 0; A[0].length>j; j++) {
        System.out.println(A[i][j]);
    }
}

Output:

1
2
3
4
5
6
7
8
9

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.