Tagged Questions
0
votes
1answer
28 views
Why wont my array average all numbers?
i have to create an array and a method call for the average. but for some reason it is not average all numbers, its only returning the last number. I have asked my instructor for help and she said the ...
-4
votes
0answers
15 views
interface directory with arrays java [on hold]
I am stuck on some work that i am trying to do. the bit that i am stuck on is trying to create my own methods for inserting a new entry into an array. deleting an entry in an array. looking up an ...
-1
votes
2answers
23 views
Selecting a range of files in a directory, Java
I have a function which lists files under a given path
public static String[] listFiles(String path)
the files are named course_1 -to- course_15.
I want to implement some functionality which ...
0
votes
1answer
40 views
Why am I getting an ArrayIndexOutOfBoundsException error?
I've built an application that will take a users input, then carry out some code dependent on the input. It all works right up until the line of code carried out within the switch case where I get ...
1
vote
2answers
40 views
How to correctly use Java generics for an array implementation of an ADT
I am trying to teach my students the proper way to use Java generics. I am teaching a data structures course, so I want them working with arrays and their own linked lists, not with the Java ...
0
votes
2answers
16 views
REST API Array woes
I want to upload a list of objects to my webserver through a REST API. I'm not sure if it's possible to do it with a REST call?
The object looks like this:
class Position {
private Date date;
...
0
votes
5answers
44 views
Length of byte[] array
String str = "123456789";
byte[] bytes = str.getBytes();
I want to make the following loop
for (int j = 0; j < bytes.length(); j++) {
b = bytes[j];
}
b will store each byte of my array, but ...
1
vote
1answer
29 views
How to correctly outprint this array in java?
I'm trying to take an input from the user for the array size and then ask the user for the array contents. This part seems to work fine but the outprint isn't working. It out prints 0's for the marks. ...
0
votes
3answers
22 views
How do I store an instance of a class created by a constructor so variables within in can be called later?
For Example: I have a deck of cards, with a constructor Card(char,int). I initialize 52 instances of card. Then using a method within Card, I call GetName() which should return a string of char + int; ...
1
vote
2answers
27 views
Finding the similarity of two String arrays
I apologize if there is a similar question asked before but only one I could find was How to find similar patterns in lists/arrays of strings
The problem is simple. There are two large arrays of ...
0
votes
0answers
47 views
Parsing issue with json
I'm trying to parse the json data that I get back from lastfm.
The method I'm interested in is album.search
The documentation requires there to be a search term for the album name, and an api key, ...
-2
votes
0answers
21 views
How i can to create an array for fixed rectangles in Java? [on hold]
how i can to create an array for fixed rectangles in Frame for Java 2D Game?
(The rectangles generated must remain fixed to window)
Thanks.
4
votes
5answers
66 views
Remove duplicates from an array in Java
I am trying to write a program which will generate a random ten integer array(integers between 1 and 6) and then I have to form another array with all duplicates removed. So {1,3,5,5,3,4,2,2,2,1} ...
-1
votes
4answers
52 views
Can someone help me with this code [on hold]
I am working on an arrays project and for some reason the code in bold is not being read can someone please say what I did wrong
int[] sumOfrows = new int[array.length];
int[] sumOfcol= new ...
1
vote
5answers
33 views
List files to String array and List files from FTP server
I'm writing apllication to synchronize two folders, remote and local, I have idea how doing that. But I'm beginner so, I have a function to listing files in local folder...
public static void ...
0
votes
1answer
54 views
Applying Math.random() to call arrays
Is it possible to use the Math.random() command to call random lines from an array or is there actually another method for this? Sorry if this have an obvious-answer but I am entirely new to ...
0
votes
4answers
59 views
Array sort and print reversed
I want to sort my array in the same as I did it here:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] numbers = new int[3];
System.out.println("Enter ...
-1
votes
4answers
25 views
Remove duplicate elements from Array [duplicate]
Hello..
My question is how to remove duplicate elements from array in java.
As we use Api remove() in ArrayList and converting ArrayList to hashset so in the same way how we will remove duplicate ...
1
vote
2answers
34 views
Varagrs, Array and parameter list
I have searched the forum but I am still unable to understand the following differences:
1) void sum(5,5,5,6,7,8,9,3,5,3,2,3,6){}
2) void sum(int[] i){}
3) void sum(int... i){}
And if ...
0
votes
6answers
43 views
Simple: Adding index to a Java array
I'm currently learning Java and refreshing what I've previously learn t, I'm making a quick test array in this class but want to add an index onto the array so the output has a number for the peanuts ...
0
votes
7answers
41 views
Java: Adding two numeric character arrays
My question seems very simple, but I've tried searching for a specific answer and have found none. I've found answers similar to what I've been looking for, but they've only managed to confuse me ...
1
vote
0answers
40 views
Unique Computational value for an array
I have been thinking of it but have ran out of idea's. I have 10 arrays each of length 18 and having 18 double values in them. These 18 values are features of an image. Now I have to apply k-means ...
0
votes
4answers
31 views
how do i make a scanner variable become an array?
How would I possibly do this? I'm trying to do this but it says the param is string and it's requires string[]
here is my code :
import java.util.Scanner;
public class Launch {
public static ...
0
votes
4answers
50 views
The program throws NullPointerException [on hold]
Not sure why it gives me the NullPointerException. Please help.
I am pretty sure all the arrays are full, and i restricted all the loops not to go passed empty spaces.
import java.util.;
import ...
-1
votes
4answers
58 views
I can't figure out how to fix the nullpointererror in Java [duplicate]
I am writing a program that takes a file and writes it's contents to an array. Then the array is sorted with a selection sort algorithm and then can be searched using the binary search algorithm. The ...
0
votes
2answers
51 views
Searching a list
I'm trying to have a user input then the program will search the array to see if the input animal is in the array. If it is in the array it should print out
" String " + animal + " was found using " ...
1
vote
1answer
25 views
How to assign indexes to values in CSV using different lengths. (Java)
I'm trying to align values in two different CSV files to like indexes. One CSV has a unix time stamp every second and the other every minute. Additionally I need to mark the indexes pn various lengths ...
-2
votes
4answers
28 views
How to times all the values together in an array list
I would like to multiply each value inside an arraylist of integers. For example,
I have an array list which contains the following numbers:
5, 5, 5, 5
How would I create an integer that ...
-1
votes
1answer
19 views
compiler error when successfully printing out initial gameboard for Conway's Game of Life
Last year I worked on Conway's Game of Life using Python. This year, I'm taking a Java Course. We have been going incredibly slow and I can hardly even understand the professor, so I'm kind of working ...
0
votes
3answers
36 views
reading 2D array text file java
I am trying to develop a GUI-based program to read the entries of a matrix from a text file. The first number is the number of rows; the second number is the number of columns. The remaining numbers ...
0
votes
1answer
21 views
How to create setOnClickListener on an array of buttons in Java
I have a dynamic array of buttons and I would like to know how to handle the onclick on every button?I want also user give the number of buttons from an extra setup menu.I try the below code but give ...
1
vote
5answers
43 views
Convert word into an array of 2 letters
I'm trying to figure out how to convert a String representing a word into an array of 2 letter elements.
For instance, I have word: believe
Then, I convert it to array of 2 letters.
The array what ...
1
vote
0answers
44 views
Java: Char Manipulation
Trying to sort an array of strings alphabetically without the use of the sort function. Code is as follows...
public static String[] sortedAdjectives(String[] original)
{
String[] ...
-2
votes
1answer
24 views
Insert element into array at given index in java [on hold]
I have a method in my program that takes an object/element and an int value as parameters. The method is supposed to use the int value as index, and put the given element on that place in my array. ...
0
votes
5answers
58 views
Deleting the last element from an array
I am trying to delete an element from an array depending on the method's argument. If the argument is the last element's position, I can't use the for loop and end up specifying an if statement just ...
-1
votes
3answers
40 views
Using a method to add a component to an array, how?
Well I was trying to make a method that will add automatically a string to an array but with no clue.
Here is what I have so far :
public static void addToArray(JTextField field , String[] ...
0
votes
1answer
29 views
Bogo sorting an ArrayList? [on hold]
The first class "cards" creates cards of different ranks and suits. It also includes a method to compare ranks of 2 cards.
public class card implements Comparable<card>
{
private int suit;
...
0
votes
2answers
37 views
How to mark the output and remove zeros?
This is a program to simulate rolling a dice 20 times and marking the most consecutive number, a dice doesn't have 0 which I don't know how to remove, I'm new to java
package diceroll;
import ...
0
votes
1answer
12 views
Add two encr/decr keys in a byte[] keyValue
I am trying to implement the Diffie Hellman algorithm to exchange keys for my crypto and i am having a problem with assigning the totals to my array. This is what i have tried:
private static final ...
0
votes
1answer
31 views
How to create/move multiple objects on a 2d array at once?
We are trying to create a shape and place it on a 2d console based board. The shapes will be made up of multiple points on a 2d array. So a triangle for example would look like this is the user input ...
-2
votes
2answers
64 views
Array, Inheritance, Method?
why do i have an error?
import java.util.*;
public class LabWork1 {
public static Scanner input = new Scanner(System.in);
public static int lengthOfList = 10;
public static int ...
0
votes
1answer
24 views
ImageComponent3D constructor wants an integer format and a BufferedImage[] array to be declared
I have a code below constructs a BufferedImage object called bufferedImage which is 2D:
BufferedImage bufferedImage = new BufferedImage(121, 400,BufferedImage.TYPE_INT_RGB);
bufferedImage.setRGB(a, ...
0
votes
6answers
74 views
how to create array inside for loop in java [on hold]
I want to create 10 arrays inside a for loop, using the names 1, 2, 3, ..., 10 for the arrays.
I tried like this, but it's not working:
int n = 10;
for(int i = 0; i < n; i++)
{
String [] i = ...
0
votes
4answers
70 views
Can someone please help me fix this Java code?
I have this following assignment every time i tried to fix an error it gave me error on error.
Given the following array of 5 rows and 5 columns, which contains the
distances between cities:
Note ...
1
vote
2answers
25 views
Generating random numbers to put in an array, if number is a duplicate draw then reroll. Boolean check is “sometimes” working
Edit: Uh well now that I pasted code into here and looked at it.. I have 2 .. "duplicate methods" .. Eclipse for some god awful reason hid the first "boolean checkforDupes()" from me. It seems to be ...
1
vote
2answers
31 views
How to make a Jbutton array of images
I'm trying to build an array of JButton images. These will have a toggle (viewable/not viewable) thus why I chose to use JButtons.
These buttons also have a background image. When I place one ...
-3
votes
0answers
31 views
How to print an array 3 columns with one for loop
for (int i = 0; i < arr.size(); i+=3) {
System.out.printf("%2d", i);
if (i + 1 < arr.size())
System.out.printf("%10d", i + 1);
if (i + 2 < arr.size())
...
0
votes
5answers
57 views
Max element of an array in Java
Ok so I'm trying to find the largest element in an array, and I realize this is not the best method to do this, it only works in some cases. Would appreciate some pointers on how to change my code so ...
1
vote
1answer
28 views
Bug help, Array out of bounds at high values
I am getting an out of bounds exception thrown when I use this median of medians code to find a given location of k. I am not sure of the exact size at which it begins throwing the error, but the code ...
0
votes
3answers
40 views
How to shuffle the contents of an array
so my program is supposed to access a text document then do all that jazz that currently works. The only problem that I can't figure out is how to shuffle the contents of an array without having them ...