There is an array in my code that includes the names to random items delimited by a /n (i think). the splitLines[] array is an organizational method that collects strings and integers separated by a delimiter in a file. The file is formatted as <<Prize’s Name 0>>t<<Prize’s Price 0>>n <<Prize’s Name 1>>t<<Prize’s Price 1>>n My goal is to assign each
Tag: arrays
how to compare 2 set values in the same arraylist in java
I have an arraylist of employees. Within this the id and name are non changeable, while the hours contracted and planned are changeable. I have managed the first 3 questions stated below, but stuck on the last one. Besides the 3 Classe below, i also have the Class Workspace. I have the Class Employee. This exends to Class Specialist And
How to use arrayList sort and manipulate the vlaue
By using Java 11, I am trying to find the average value inside the ArrayList. The algorithm i want to develop is ((value inside list/maximum value)*100)/length of list). I got number format runtime error while I run the program. java.lang.NumberFormatException is the error i got. enter image description here Answer I find two issues with the code above: The parsing
Check if multiple objects have same value of a field in java and remove duplicates based on other fields
So I have a list of objects. Suppose they have 2 fields startDate, endDate(data type is timestamp). So if startDate is equal to startDate of another object then I have to choose the object with higher endDate. How can I achieve this efficiently. I can use 2 for loops but that would have a high time complexity. Any better way
Returning an int array in Java
So I need a script that returns an array of a text document. The document is all numbers. Everytime I try to run it I get this message “This method must return a result of type int[]” this is under the checker part. I am trying to return it to another class so that I can use the array for
Not able to print the first element in an array (Inputed by user)
I am trying to print the types of vehicles that are being rented. The issue I’m currently having is that the print statement only prints the second type of input from the user. Here I have the do loop where the user inputs the number of vehicles that they are renting. They rent less than 3 vehicles, which is what
How to get the maximum occurring character and its occurrences from a user inputted String sentence?
I have a program that asks the user for a String sentence and output its maximum occuring character and its occurences. My issue here is that the function that counts the max character and its occurrences only counts that maximum character and its occurrences only for a single word(that is all lowercase) and not a full sentence or a word
Getter, Setter & NullPointerException
Firstly, I am trying to assign the value for array I initialized locally. The class type of the array is stored inside another class and the variable is private so I am using getter and setter to set the value. But it showing “Exception in thread “main” java.lang.NullPointerException at room.Test.main(Test.java:26)”, below is my code for the test.java: Below is the
An efficient way to check index out of bounds
I have an n x n 2D array, and need to connect random points to four neighbors (sorry I added the picture, but it seems one has to click on the link for the image to show). Click to see the image I would like to use code like this: The problem I am having now is the index out
Reversing digits in 2D array
I was trying to reverse the numbers in this 2D array, but I happened to be reversing only first and the last numbers. So far I have done this, but don’t know where is the mistake and how to fix it, so that every digits are being reversed, not just first and the last: Answer Ok, here is another way