I am working in a small task that allow the user to enter the regions of any country and store them in one array. Also, each time he enters a region, ... |
I am working in a small task that allow the user to enter the regions of any country and store them in one array. Also, each time he enters a region, ... |
I am trying to print out the largest number in a 2D array. My problem is that my output are three numbers instead of one - the largest. Why?
Here is my ... |
I have a [20][20] two dimensional array that I've manipulated. In a few words I am doing a turtle project with user inputting instructions like pen up = 0 and pen ... |
|
public void fill(ArrayList<String> a1)
{
int i = 0;
while (i < a1.size())
{
if (i == 0)
{
...
|
Ok so I did what the thread suggested..sorry I should have searched first by the way. So it said to use the toString method...i tried that, and it gave me a printout of the same characters which it says in the thread that they are hashcodes, but it printed multiples equal to the size of the 2D array which is 9. ... |
|
I'm not really sure what you're doing with printing lines there ... "_________" for example ... but generally, you'd want to have two nested for loops. The idea is: for each rank, print out the pieces at each file in that rank, then print a new line, then go to then next rank. (Rank = row, file = column.) |
Code: //cities.txt kinstown 45000 RoseHall 78000 #### man can 5675 Kinstown RoseHall 564 Uproad Augustine 678 #### import java.io.*; import java.util.*; class City{ private String cityName; private int population; City(String city, int pop){ cityName = city; population = pop; } public String toString(){ String str; str = "cityname " + cityName+"\n"+ "Population " + population+"\n"; return str; } }//end of City ... |
two dimensional array print Printable View 04-26-2010, 12:10 PM Myles two dimensional array print ok so i'm stuck with this problem. Trying to print out a two dimensional array of a timetable(done) but on the right side, the day name has to be listed, but from another array. This is what i'm aiming to print out Code: 9 10 11 12 ... |
I know this is against the rules but it keeps logging me out when I enter that thread for some reason. Anyway to the point your problem is here for (int i = 0; i< DAYS.length; i++) { System.out.print(DAYS[i]); } instead you want to initialise a variable outside the whole loop, then add one to i without the for loop inside. ... |
I am making a program that will navigate a path in a maze I created with a 2D Array. I have everything mostly in place and am trying to print out the maze... everything complies fine but I get this error when I try to run it: Here is my code: Java Code: import java.io.*; import java.util.*; public class Maze { ... |
private int[] mySpeed; private int[] myAngle; private double[][] myDistance; public Catapult(int[] speed, int[] angle) // constructor; initializes all private variables { myDistance = new double [speed.length][angle.length]; mySpeed = speed; myAngle = angle; } public void calcTrajectory() // mutator method to fill 2-D array { for (int row = 0; row < myDistance.length; row++) { for (int col = 0; col < ... |
|
|
|
|
jackosticks wrote: I know it has to do with the code inserting into the array in a slot that does not exist, but hpow can i work around this ???? By not trying to insert data into non-existing array slots. The stacktrace tells you exactly where your bug is. On line 43 you're accessing your array out of bounds. Fix your ... |