Skip to content
Advertisement

Tag: for-loop

How to fully print outer loop before inner loop (Java)

My goal is to print a chart that displays “enemy” number, x and y coordinates, then their distance in respect to the other “enemies”, but with my following nested loop below, the enemy number, and coordinates are reversed with the distance numbers. I’ve tried adjusting the position of the codes, but they don’t seem to fix the issue. Answer

Separate “for” loop iterations

How would I go about making each iteration of my four loop be random. The outcome as of now makes all 20 sentences put the same output, although it is choosing random words each time from the four arrays created in static class OuterWord. I have omitted the parts of the code that I don’t think are necessary including the

Implementing a printAnimals method

I am trying to implement a printAnimals() method that prints the ArrayList for dogs or prints the ArrayList for monkeys, or prints all animals whose training status is “in service” and whose is Not reserved, depending on the input you enter in the menu. I am trying to correctly write a for loop for both ArrayList that contains if statements,

Check if a char is in a 2D array in java

I have been working on my homework of creating a simple chess program. The chessboard is a 2D array, named board. The pieces are all single chars like R,Q,K, and empty space is filled with a ‘ ‘ char, so a space. The method get should return the char or whatever is there on the coordinate (x,y). And the problem

Advertisement