I’m a beginner in Java programming and I created a program that accepts 10 numbers as input from users and prints them. The first section is using for loop and the second section is using while loop. The first section works properly and the second section isn’t displaying output. Could anybody help me? } Answer You are not resetting variable
Tag: arrays
Maximum number of tasks to be performed
I’m stucking in a problem. I know dp can be applied here, but not getting it. Consider a part of the positive number line starting at 0 and ending at 10^9. You start at 0 and there are N tasks can be performed. The ith task is at l[i] and requires t[i] time to be performed. To perform ith task,
How to push/get data from Firebase and add to a bidimensional array using Java?
I already have TOPSIS algorithm that can calculate data from an array[][]. Now I’m going to use the data from: dummy data: to database’s data My Item_pc.class Condition: I can get data from firebase using arraylist I can calculate data using dummy array with TOPSIS algorithm problem : how to calculate data from firebase with TOPSIS algorithm? I have trouble
How do I pass different value to each thread in ExecutorService?
Lets say I have an array num_array = [0,1,2,3,4…30] and I have a multi-threading function like this I wanted to know how I can pass num_array[0] to thread 1 and num_array[1] to thread 2 … num_array[24] to thread 25 Answer Just loop over the array and pass each runnable the element: Note that you should not assume the order of
Create multiple Lists from one (Group List’s Objects by a specific field)
Given that I have the array of : gives me : I want to create a new array which is grouped by the 3rd parameter of surname object. So that my array becomes So that when we do .get(1) we would get object of kasis and samika. Need the help in respective to java 8. I heard that we can
How can I split string elements of an array and add them to another?
Using an array list of names, I am trying to split the first names and surnames using a for loop. The code works but when splitting the names using a substring it goes from 0-x (x being the space between the names) but it reads from 0 each time and adds each name multiple times until it completes. How can
How to determine whether a switch case was chosen?
I’ve got a project that I am working on and it requires I have an array with a set size of 5. I then need to gather data from 4 different cases, and store them 5 times. (One of the cases can be used multiple times, case gets specified by user input). Here is what I have tried: I planned
Appending column at the end of a csv file java
I have a csv file and I have some data in it and I want to append a column in it. e.g: I want to append that Marks Column through code. The problem I’m getting is The data is getting written 2 times and also the on the first column (Except the first one). How can I prevent it from
Using “put” method of JSONObject in for loop (java)
I’m trying to use JSONObject’s put method in for loop. But I’m not getting Expected output. Expected output: OutPut I’m getting: here is my code: Answer Have you tried moving the construction of infoObj inside the loop. By having it outside, you’re maintaining state across loop iterations. I suspect you’re just updating the same json object each time and adding
Copy all values List to Jackson JsonGenerator Array directly instead of looping over it
I am creating a JSON file using the Jackson JsonGenerator for which I need to add the elements from List<String>. This List consists of the JSON Fragments which needs to be added to my final JSON file. As of now, I am looping over the List<String> and adding them to my Jackson JsonGenerator writeRaw one-by-one. This is working fine as