So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far
private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){
boolean solved = true;
for(int i=fromRow; i<toRow; i++){
for(int j=fromCol; j<toCol; j++){
if (x[i][j] == ('*')){
//do something
}
}
}
return false;
}
the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?
depth is a variable for the row in the triangle. My problem is that i need the solution to be recursive and i am having trouble doing this. So far i have
public static int findMax(int[][] array,int depth) { if (depth==0) return array[0][0]; else if }
I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified."
I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in
This is after many tries and i still can't change directory and i keep getting the same message.
I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified." I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in
This is after many tries and i still can't change directory and i keep getting the same message.The book I am using to learn Java is "Java How to Program: Tenth Edition" from Paul and Harvey Deitel.
After install when i run sqldeveloper command then it prompt me for jdk path
1. Which I don't know how to find 2. When I try to give /usr/bin/java1.7.0_09/ and enter then it give me below error
/usr/bin/java1.7.0_09 Error: /usr/bin/java1.7.0_09/bin/java not found Type the full pathname of a J2SE installation (or Ctrl-C to quit), the path will be stored in ~/.sqldeveloper/jdk
I have some N*M matrix or N*N matrx , and there's a "worm" that can start from any index in the first column, or, any index in the first row. i need to choose the longest worm that satisfying this :
The index that comes after the index before him must be greater then 1. and i must use recursion, also for helper methods. no loops at all. that's it. i'm having a problem to find the longest worm in the matrix.
My idea was to create an helper array and assign to the array indexes a variable that will count the steps of the worm and finally assigns in to the helper array index. then i used findMax method to find the max value in an index. and thats will be the longest worm. i wrote a lot of code so i wont put it here. i will say that i'm close. if the longest worm is 6 i get in my output 7.
First of all, i am using ubuntu and jdk8. My problem: displaying the current path of a file in my system Approach: I have a file called dummy.txt in a given directory which have enough permissions and i did the following:
I expected to see displayed the current path of the file without the name of the file but it is showing a different path. I just want to display the current path of the file without the name.
Trying to find cheapest path recursively, given a grid a integers trying to recursively find the cheapest path from the top to the bottom. cheapest being the sum of the path. I think I've made my code over complicated. recursive things are usually much more elegant
import java.io.FileInputStream; import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; public class trial { public void readFile(String fileName)
I have a 2D array that is of type int[][]. it is populated with 1's and 0's. I need to create a method that allows me to search from the top row finding a possible path to the bottom--the path is a path of connecting cells containing 1. I need to create an array that stores the cells that are needed to be searched. When the search carries out, for each cell stored it needs to check the cells to the left, right, below and above the current cell.
I also need to create a variable to store the current cell. I thought initially it would be an int but it can't be because it needs to hold the the index of the current cell. and any of the cells searched that are an immediate neighbour of the current cell are added to the storage array.
I have these instructions but I am having trouble converting into code
Finding a path through vegetation from the top row to the bottom row: The idea is we will start from a cell in the top row and advance below for as long as we can. Since we are still not done exploring a cell until we have explored ALL it’s vegetation neighbors, we will add the cell to an array of cellsToExplore and only come back to it if the current cell we are examining is fully explored. Here is pseudo-code of the algorithm !
• Create array cellsToExplore (what size should this array be?)!
• Create an integer count that stores the number of cells in cellsToExplore!
• Go through the top row and add ALL vegetation cells to cellsToExplore!
• Create a variable to store currentCell we are exploring and set it to null.!
• while count > 0 do!
- set currentCell to the last cell in cellsToExplore (last cell added to the array).!
- label currentCell as burning vegetation!
- If the currentCell is on the bottom row then we return true (we found the path).!
- if the cell below currentCell is vegetation then add the cell below to the cellsToExplore array.!
- else if cell to the right of currentCell is vegetation then add the cell to the right to cellsToExplore!
- else if cell to the left of currentCell is vegetation then add the cell to the left to cellsToExplore!
- else if cell above the currentCell is vegetation then add the cell above to cellsToExplore.!
- else remove the currentCell from the cellsToExplore (we are done with this cell). !
So far i've built an array of char W= wall, O=open, R= rat, and P= path
I have another class "RAT" which will navigate through the maze. so im having trouble with the method to get the position of the rat when it is navigating through maze. this is what i have.
public class FinalMaze { static char[][] mazeArray = new char[][] { {'o','o','o','o','o','o'}, {'o','w','w','r','w','o'}, {'o','w','p','p','w','o'}, {'o','w','p','w','w','o'}, {'o','w','p','p','w','o'}, {'o','w','w','p','w','o'}, {'o','w','w','p','w','o'}, {'o','o','o','o','o','o'}, };
I am doing an assignment which involves creating a maze and a ball that needs to go through the maze to an end tile then stop the scenario. The maze is made up of 208 buttons in a Jbutton Grid layout. I am replacing certain buttons with a brown tile icon to make up the maze. The ball needs to run along those brown tiles as its path and not be able to move off the brown tile icon images.
I have built the maze and have got quite far with this but now I am stumped on the concept of keeping the ball within the boundary edges and on the brown tiles. I have been told to use if statements, but not had the process explained to me in a way I can understand.
im having 2 simple problems that are for somereason going above my head right now.
1: i need to start the program at the first possible position (row 0 col 0) 2: i need to be able to read multiple mazes in one file.
Code:
import java.io.*; public class Driver { private File mapFile = new File("map.txt"); private char[][]maze; private char pathMarker = '2'; private int row,col,ndx=0; public static void main(String[] args) { Driver d = new Driver();
I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backing File="$IDP_ ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder.i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time.Problem: If i change the folder name from my root path in my machine after i run the server,the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.
So i want to change it to relative path instead absolute path. What is the best way to do it? Please look at code below:
[ // Getting the current working directory String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;
I am using the shortest path algorithm to determine the connection between individuals within a given array. The array is written into the code and not read from external files.
When I am having problem is .. i am having problems how to prompt the user for the starting point or vertex and read that prompt to determine the starting point in the array. I know that this code :
computePaths(v0);
determines the starting point. i want to read "v0" from the user prompt.
I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.
I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement
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];
So as part of my program I have to find the corners of an array (the array can vary in size but is always square) but I'm not exactly sure how to do this. I thought of one possible way but I am not sure if I can do it or how to write it,
if array[row][col] = [0][0] or [row length][col length] or [0][col length] or [row length][col length].
I'm just giving examples of what I am trying to find here I know none of these are actual syntax. I don't even know if I can check whether an array's coordinates are equal to coordinates on that array or not. How I can write this or if there is another way to do it? If yes, what about edges of the array?
I have a given array of numbers, and I have to find the longest decreasing sub-array, but the thing is that the elements don't have to be next to each other!
For example, the longest decreasing sub-array for this array : 546 -156 165 -156 -56 -13 5
is 3 (check the bold numbers)
Until now, I have nearly finished my code, but I have one problem...
private static int decreasing(int[] a) { int result=1, temp=0, br=1; //Checking all the elements one by one: for(int i=0;i<a.length;i++){ temp=a[i]; //placing the element on a temp value
[Code] ....
The problem with this code is that it's not smart.. let's say I have : 100 -500 90 80 70
Once it hits -500, none of the other if's with pass....
what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:
import java.util.Random; import java.util.Scanner; public class tnArray { public static void main(String[] args) { int [] array;
[code]....
Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
How can I find the overall averages of the columns in this array?when i run my code it gives me an output that looks like this (showing me wrong averages): 0 1 2 3 overall grade
I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.
import java.util.Random; public class Projektas { public static void main(String arng[]){ int i,j; int A[] = new int [10]; int B[] = new int [10];;
I made a method which takes values from a data set and finds out which one is the highest value. When it finds the highest value, it returns the country which is associated with the value. Here's the data set.
"Country""Total CO2 2005 (million tonnes)""Road CO2 (million tonnes)""Road CO2 per person (tonnes)""Cars per 1000 people" 10 USA5951.131530.35.16777 UK2573.4119.681.99470 Italy476.08116.862592 Germany841.78150.211.82550 Canada553.02123.423.82562 France414.03128.132.04477 Russia1575.44114.690.8178 Japan1254.47224.241.76447 China5100.6228.020.317 India1147.4691.060.18
So if the number was 5951.13 then the program would return USA. How do I do that? I've already started on trying to get this code to work but it doesn't seem to compiler so what's wrong with it?
public static CO2Data highest (CO2Data [] arr2){ Scanner sc = new Scanner(System.in); CO2Data highestindex = arr2[0]; CO2Data currentcountry = arr2[0].getCountry(sc.nextLine());
[Code] ....
Also the array is a CO2Data array which is part of the following class:
public class CO2Data { //The CO2Data class will be called in other methods
private String country; //A private variable will prevent other users from accessing and changing these variables.
private double totalCO2; private double roadCO2; private double CO2PerPerson; private int carsPerPerson; public CO2Data() { country = "";//this sets the initial values for the different variables