I am trying to add Scanner inputs into an array and I am trying to search for the element in an array using a for loop. The for loop looped through all the elements and print out “Not here” when names[i] is not equal to the Scanner input. How do I fix this issue ? Answer
Tag: for-loop
How to print number 1 to 10(in that sequence only)using loops(java) if int i = 10
Output must be 1 2 3 4 5 6 7 8 9 10 I have tried While loop but it prints from 10 to 1 Answer Assuming you must use i with an initial value of 10.
Having two for loop in a single Java Method
I have a method shown in the code below, I have a hashmap buffer and queue with several list in both. I want to search a particular message to set it true when it is stable; the message could be in either the buffer or queue. is it alright to lump the two for loop within a single method? or
Method that takes an int array and a value and returns the index of that value in the array
I’ve spent like an hour trying to figure this one out and I couldn’t. This is an exercise for a Java elective course I am taking and I could use some help. Write a method linearSearch() that takes an array of integers, and an integer value. It should then return the index of the value inside the array (by using
java swing nullpointer exeption whilst adding buttons [duplicate]
This question already has answers here: What is a NullPointerException, and how do I fix it? (12 answers) Closed 8 months ago. solution So i was trying to do a java-swing-gui for a school project and therefor I have to add 72 Buttons (idk) to a JPanel element. I tried using a for-loop: but it didnt really work out and
Trying to explain a a java for loop which requests JSON objects and requests for Queues
I’m trying to do a written report on some code and I found one on Youtube. However, I don’t understand how some of this loop works. I understand that it goes through every item in the list and fetches each value for each variable and that it then adds all values to a list which is presented in an XML
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