Skip to content
Advertisement

Tag: arrays

Sort List of Strings arrays in Java

I’m trying to make a program that consists of an array of Strings . now I need to sort them in order ‘PJ’, ‘GHS’, ‘FJ’, ‘PAS’ and date. input : output: //Always ‘PJ’, ‘GHS’, ‘FJ’ then ‘PAS’ Answer You should consider using custom java classes instead of String Array. Find below an example to do it .

Arrays variable in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I am new to array concept there is something i cant understand that is i have read somewhere that when we intialize an array like

How do i pass variables into methods – java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I need to use a variable from one method in another. Here is the code: Here is where it needs to be used: my current

Find all matching elements in Array – Java

At the moment my code is only giving me the first matching result. The user inputs their desired room price and at the moment it will only display the first match. In the case the user inputs ’60’ to the console it should display 3 results. I imagine i’ll need another forloop and if statement after it prints to the

Why is function not returning array in Java?

I’m making a small script to calculate the Fibonacci sequence by having an array to give how many digits i want, I just can’t figure out why my fib function is saying that there is no array being returned. Code: Answer It’s a matter of scopes. Your only return statements is within the for loop, but if your for loop

How to replace even values in string with ASCII value?

Suppose I have a string as ABCDEFG. I want to replace the even values of this string with their ASCII value. How should I do? Answer You are almost there, you simply need to build the resulting string. Strings are immutable, so replacing would create a new String each time. I would suggest a StringBuilder for this task, but you

Dividing a 1D array into a 2D array

So I have homework that asked me to: Write a method that takes two parameters: an array of integers and an integer that represents a number of elements. It should return a two-dimensional array that results from dividing the passed one-dimensional array into rows that contain the required number of elements. Note that the last row may have less number

Advertisement