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
Tag: arrays
Trying to read a 2D Array for a Value and Display its Location. Encountering Issue Delivering a message when it isn’t found
I am reading through a 2D Array and when it displays every instance of the target integer to find, I can’t seem to find a way for the nested for loop to display a message Number not found or something like this. The 2D Array has 8 Rows and 9 Columns. Here is the program below: When it can’t find
Sort 2d String array by integer in first column
I have a 2d array in Java 8: String data[][] = new String[i][2]; And it looks like this: Player1 8 Player5 3 Player3 9 Player4 5 … and I want to sort it to have the highest score at the top: Player3 9 Player1 8 Player4 5 Player5 3 How can I sort this or is there a better way
I want to swap characters of string in java but it returns garbage value can you please tell me what is wrong with my code
I want to swap characters of string but this program returns garbage value. Can you please tell me what is wrong with my code. Answer You have to use constructor of String class. Then it will work fine.
How to sort array based on multiples of 3 using Java
I have an array like this one- {1, 2, 3, 4, 5, 6} I want to sort it in the order of multiples of 3 with remainders 0, 1 and 2. (the first group is multiples of 3, the second one is multiples of 3 with remainder 1 and the last one is multiples of 3 with remainder 2) and
Add strings to an array of strings inside for loop using java
I have a for loop and I want to add strings to a string array inside that loop. How can I achieve that? The output should look like this- Answer You can create the result array with a size that matches the registration array length, since you know you want to create one result for each registration entry. You then
How to get my scanner to recognize the words i have for it
I’m pretty new to java and coding in general and am trying to figure out how to get this game to work for a project at school. It is meant for you to type in a month and it will then ask you to choose a day, however when I input a month it always just says its an invalid
How to select the complete JSON node if any key-value pair matched inside the node?
I have JSON some thing like below I am aware how to iterate through JSON Array based on key and extract the values of that particular key. But stuck with one scenario let say instead of key i have value with if i have value ‘s1’ with me i want to traverse through above JSON and if it matches with
Java: Generate array from 1 to n with step size
I have trouble with a quite easy task. I want to have an array from 0 to a value n with step size t, always ending with n. Example 1: n=10, t=3, array={0, 3, 6, 9, 10} Example 2: n=20, t=5, array={0, 5, 10, 15, 20} Example 3: n=1, t=1, array={0, 1} I have code which I have been using
I need help Returning a string representation of my circular queue
I am trying to returns a string representation of my circular queue heres what I have so far. (Im not allowed to use/import other libraries in my code) My public String toString( ) doesn’t return the right numbers on my test driver. I think it has something to do with it not circling the array. And my driver: Help would