All Permutations Of 2 Coordinate Int Array
Apr 12, 2014
I have a set of 2D arrays, structured as so: int[][] cage = new int[someLength][4]. Each array has a set column length of 4; the first two columns are all that concern us with this problem. They are used to define the row and height respectively of a point (e.g. 2,4).
What I need is to generate all possible permutations of the points using both row and column coordinates from the 2D array. I found a working method to generate all permutations for 1D array of ints here: [URL] ..... , under update 2 of the first answer.
Here is an example of a possible input and corresponding output desired:
In: (1,0)
(1,1)
Out:(1,0),(1,1)
(1,1),(1,0)
Ideally the result will be stored in a 2D array of ints.
View Replies
ADVERTISEMENT
Apr 12, 2014
I have a set of 2D arrays, structured as so: int[][] cage = new int[someLength][4]. Each array has a set column length of 4; the first two columns are all that concern us with this problem. They are used to define the row and height respectively of a point (e.g. 2,4).
What I need is to generate all possible permutations of the points using both row and column coordinates from the 2D array. I found a working method to generate all permutations for 1D array of ints here: My link, under update 2 of the first answer.
Here is an example of a possible input and corresponding output desired:
In: (1,0)
(1,1)
Out:(1,0),(1,1)
(1,1),(1,0)
the result will be stored in a 2D array of ints.
View Replies
View Related
Oct 2, 2014
I have 5 numbers between 0 to 13 in ascending order stored in an array. They may have repeats. I want to perform permutations and figure out the number of running pairs (minimum 3 numbers in a pair. Ex- 012, 345, 456, 1234, 78910) that I can make with these command line inputs that I get.
Lets say my user input was 01123. For this sequence I'll have the following pairs-
012
012
1234
1234
123
123
0123
0123
There are same repeated sequences because there are two 1's hence same pairs using different 1's.I have the input in an array so I'm wondering if there is any inbuilt class for arrays that would let me do this. If not, whether I can pass it into a collection and then find its permutations. Following which I traverse through the sequences and update a count for each running pair generated to pass onto an array in another variable to perform some other functionality. If this is viable how to implement this in code ? I'm new to java and am not familiar with the classes available.
View Replies
View Related
Aug 7, 2014
how the code is getting all the permutations of a string with recursion. The following code works correctly but I am having trouble grasping what it is doing.
public class Main {
private static void permutation(String prefix, String str){
int n = str.length();
if (n == 0)
System.out.println(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i),
str.substring(0, i) + str.substring(i+1));
}
}
public static void main(String[] args) {
permutation("", "ABCD");
}
}
I see that each character is being appended to prefix through each iteration. So I know it adds "A" then "B" etc etc. I can follow it up until the "D" is appended to the prefix string. After that I don't understand how the D moves back to the str string and then the C moves back to str followed by the D moving back to the prefix string. I have stepped through the code many times in my debugger but still don't see how it moves back to str and knows to send D to prefix and not to send C. I feel I don't understand how recursion behaves therefore I can't follow.
View Replies
View Related
Apr 16, 2014
how I can use this class:
Java Code:
public class Coordinate{
public int x;
public int y;
publ Coordinate(int x, int y){
this.x = x;
this.y = y;
[code]....
How would I use Coordinate in the second code?
View Replies
View Related
Oct 18, 2014
I've been pondering about this algorithm for about a week but I'm still not able to write a "fast" working method/algorithm to solve the Number-of-paths-exercise we were given in my class />
So here's the task:
Write an efficient java program "Paths" which solves the following task:
- Read input n ∈ N and give output a(n) which is the number of paths from (0,0) to (n,0)
it is not allowed to go over the diagonal (m,m) and also not below the x-axis (m,0)
Here are the allowed steps:
u = (1,1), U = (1,4), d = (1,−1), D = (1,−4) and H = (1,0)
steps are performed in a two-dimensional-coordinate-system!
View Replies
View Related
Mar 6, 2014
Ok Im trying to create a code right now that will take a table of rectangular coordinates and convert them to Polar coordinates in the constructor. I will eventually calculate the total distance between all points in the calculateDistancePolar method but for now I am using it to test.
It doesnt like line 29 and 31 of the class Polar and I cannot figure out why.
public class Test {
public static void main(String[] args) {
double[][] coords = {{86.92, 2.47},{70.93, 27.81},{97.74, 34.36},{30.90, 35.14},{51.66, 31.70},{0.830, 21.77},{55.91, 66.62},{32.92, 75.23},{65.26, 72.53},{83.90, 4.710}};
System.out.println("X,Y Coordinates are:");
outputArray(coords);
Polar myTest = new Polar(coords);
[Code] .....
View Replies
View Related
Feb 3, 2015
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
/**
An applet that shows a rotating globe.
[Code] ....
View Replies
View Related
May 24, 2014
I'm having a random x and y coordinate generate and I need to check if the coordinates are inside of a right triangle on this imaginary coordinate plane.
View Replies
View Related
Aug 22, 2014
This program deals with a variation of the geographic coordinate system with Greenwich at 51° 28' 38" N. The program will be adding the three values of one coordinate to the three values of the second coordinate. Though the maximum value for seconds and minutes is 59, the user can enter values greater than that number when prompted. The maximum degree is 360 for this assignment though the user can enter values greater than that number.
View Replies
View Related
Nov 8, 2014
So I need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the array and for the assignment i have to use a for loop to traverse the array. The method header for the displayArray method is:
public static void displayArray(int[] array)
This is what I have done
public class RandomIntegers {
static int numbers = 0;
public static void displayArray(int[] array) {
System.out.println(numbers + "Numbers Generated");
[Code] .....
View Replies
View Related
Mar 24, 2015
I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.
I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.
The list consists of the following wifi related values:
MAC-Adress, SSID, Timestamp, Signalstrength.
These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.
The catch is, we are not allowed to use any of the following:
java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.
So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.
Below is my Code (Its still an active construction zone):
public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];
[Code] ....
View Replies
View Related
Feb 13, 2014
i am working on the same project and i got the code to make them print going down but not sideways.
public class ArrayofHope
{
public static void main(String args[])
{
System.out.println("Decimal Character
");
for(int j = 65; j <= 90; j++)
{
System.out.print(j);
System.out.println(" " + (char)j); //Character
}
}
}
View Replies
View Related
Aug 3, 2014
I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9
6 1 2
5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*;
public class Spiral
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int n=Integer.parseInt(br.readLine());
[Code] .....
View Replies
View Related
Nov 15, 2014
We were given a class lab that asks us to write a program that create a multidimensional array ( 5 x 5 ), populates the array using nested loops with letter from A until Y, and displays the array to the screen. and the result should look like this:
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
How to write this program.. I have tried all my best but the results are not coming like this..
View Replies
View Related
Jun 21, 2014
I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.
This is the incorrect line: ar[r] = maze[r].clone();
My code:
private String[][] maze = {{"*","*","*"," ","*","*","*","*","*","*"},
{"*"," ", "*"," "," "," ","*"," ","*","*"},
{"*"," ","*","*","*"," ","*"," ","*","*"},
{"*"," "," "," "," "," "," "," "," ","*"},
{"*","*","*","*","*"," ","*","*","*","*"},
{"*","*","*","*","*"," ","*","*","*","*"}};
//private String[][] mazeCopy = copyMaze(new String[6][10]);
private <T> T[][] copyMaze(T[][] ar){
for (int r = 0; r < ar.length; r++){
ar[r] = maze[r].clone();
}
return ar;
}
My compiler says: Required: T[]. Found: java.lang.String[]
Since ar[r] is an array and .clone() also returns an array why is this line incorrect.
View Replies
View Related
Jun 15, 2014
Write a method that returns a new array by eliminating the duplicate values in the array using the following method header: public static int[] eliminateDuplicates(int[] list). The thing is that I found the working solution that is written below, but how it works. How to eliminateDuplicates method done with flag and flag2.
Here is the code:
Java Code:
import java.util.Scanner;
public class Exercise06_15 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int[] numbers = new int[10];
System.out.println("Enter ten numbers: ");
[code]....
View Replies
View Related
Oct 13, 2014
I am receiving an ArrayIndexOutOfBoundsException for the following code, which moves a creature through a 2D array maze. I have altered the clauses of the first if statement for the four direct methods (north, south, east, and west) multiple times (i.e. x + 1 >= 0 && x > 0 && x - 1 > 0 && x < array.length...etc). However, while the code occasionally runs, more often than that it returns this exception. Catching the exception seems like a poor workaround though if worst comes to worst I'll do that.
I included only the relevant functions of the code:
public boolean goNorth(char[][] array) {
boolean success = true;;
x = getX();
//x = this.x;
y = getY();
//y = this.y;
if ((x - 1 >= 0 && x - 1 < array.length)
&& (y >= 0 && y < array[x].length)) {
[Code] .....
View Replies
View Related
Feb 7, 2015
I am passing input from the user to a method that will initialize an array of the data (scores in this case). The method is filling the entire array with the last input value.
array initializer method
Java Code:
public static float[] inputAllScores(float validScore) {
float[] diverScores = new float[7];
for (int i = 0; i < diverScores.length; i++) {
diverScores[i] = validScore;
}
return diverScores;
} mh_sh_highlight_all('java');
[Code] .....
View Replies
View Related
Oct 10, 2014
So I have this stack. I'm writing out all the operations and what not but I'm having trouble bypassing this "generic array creation" problem. I'm meant to be creating an array based implementation of a stack and from my research from google and my various attempts at things, I have not found a solution that works.
In addition; I have all the operations written that I need except for one final one. And that is clear(). clear() is meant to empty the array, essentially it is a popAll() method. Then all I need to do is set up so I can print out the arrays and I should be able to handle everything else.
StackInterface:
/**
An interface for the ADT stack.
*/
public interface StackInterface<T>
{
/** Adds a new entry to the top of this stack.
@param newEntry an object to be added to the stack */
public void push(T newEntry);
/** Removes and returns this stackÕs top entry.
@return either the object at the top of the stack or, if the stack is empty before the operation, null
*/
public T pop();
[Code] ....
View Replies
View Related
Feb 16, 2015
filling out a Random array: An Array of Specific Length Filled with Random Numbers This time what I need to do is take the elements from this Random array and assign them to a new Byte array:
for(int i = 0; i < limit-10; i++) {
Random dice = new Random();
int randomIndex = dice.nextInt(array.length);
if (array[randomIndex] < 128) {
System.out.print(array[randomIndex] + " ");
} else if (array[randomIndex] >= 128) {
System.out.print(array[i] + " ");
}
}
byte[] noteValues = new byte[]
{ 64, 69, 72, 71, 64, 71, 74, 72, 76, 68, 76 }; //This is the byte array filled manually!
I've tried amending the manual input to fit in with the Random array, as follows:
byte[] noteValues = new byte[]
{ array[randomIndex] };
In this case, however, the Byte array can't interpret the int values. Also, if the Byte array is outside the 'for' loop, array[randomIndex] cannot be resolved.
View Replies
View Related
Apr 19, 2015
Trying to convert 2D array to String using toString() to be able to print the array but when I try to use it I just get the memory location
public class Forest
{
private int h;
private int w;
private double p = 0.7;
private int[][] f;
Forest(int w, int h)
[code]....
View Replies
View Related
May 17, 2014
JButton btnNext = new JButton("Next");
btnNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for (int i = 0; i < bkSorted.length; i++)
{
textArea.append("
" + bkSorted[i+1]);
}
}
});
When I click the button, it displays the whole array, instead of just the next array position. What am I doing wrong?
View Replies
View Related
May 13, 2014
I need to write a method that accepts an array of ints and squares each element of the array. No creating new arrays and no returning any values.
public void squareInts(int[] ints) {
for(int i = 0; i < ints.length; i++) {
ints[i] = (ints[i] * ints[i]);
}
}
View Replies
View Related
Feb 13, 2014
I have double checked this code over and over and I just can't find the problem.
What I'm trying to do is take a file and input it into an 2D array.
Ultimately, I should convert the array of integers to an array of characters, then print it out. The file contains a set of ASCII values.
After printing it out, I should then create methods to manipulate the image produced.
Using 2D arrays is a requirement for this exercise.
I think that somehow I'm overcomplicating this and the solution is a lot more simple than I think, but I can't think of what to change.
The error I am getting is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 40
at main.main(main.java:17)
Java Code:
import java.util.*;
import java.io.*;
public class main {
public static void main(String[] args)
throws FileNotFoundException {
String[][] data = new String[22][40];
[Code] .....
View Replies
View Related
Apr 12, 2015
I have an array of Strings, one on each line and I need to convert them into an array of char's.
For Example:
This
is
an
Example
of
what
my
input
is.
In order to accomplish that I did the following-
String[] lotsOfText = a.gettingAnArrayAsAReturn();
char [][] myCharArray = new char [lotsOfText.length] [lotsOfText.length];
for(int i=0; i<lotsOfText.length; i++){
for(int j=0;j<lotsOfText[i].length();j++){
myCharArray[i][j] = lotsOfText[j].charAt(j); }}
But whenever I try this and then try to print the output :
for (int i = 0; i < lotsOfText.length; i++) {
for (int j = 0; j < lotsOfText[i].length(); j++) {
System.out.print(myCharArray[i][j]);
}
}
I get nothing. I'm not sure what's the flaw in my logic, is it the char array initialization that's wrong or is it something else ?
View Replies
View Related