i think the for loop increments to store the next value in the array. But my time is up anyway. Submitted 5 mins ago. :/
Type: Posts; User: javaman1
i think the for loop increments to store the next value in the array. But my time is up anyway. Submitted 5 mins ago. :/
yea i mis read when u said to place it outside the loop.
this is what it prints
--------------------Configuration: <Default>--------------------
an ID [1280, 1280, 1280, 1280, 1280, 1280, 1280,...
this is what it printed
--------------------Configuration: <Default>--------------------
%d [1280, 0, 0, 0, 0, 0, 0, 0, 0, 0]
%d [1280, 1280, 0, 0, 0, 0, 0, 0, 0, 0]
%d [1280, 1280, 1280, 0, 0,...
yea i saw the posts but that does not tell me anything. How is the logic incorrect?where? how do i changed the logic?
import java.util.*;
import java.io.*;
public class Spaceship{
public static void main(String[]args)throws IOException{
Scanner in = new Scanner(new FileReader("distances.txt"));
int []...
ok now its just printing the last number from the file 10 times
int [] distance = new int [10];//array of size 10
int dist=in.nextInt();//read first value from file
int i;
while...
i did that but when i run the program im getting this:
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.util.NoSuchElementException
at...
1.read value from file
2.store in array.
i did that but its not working
ok but how. I dont see where im getting the error. and i placed println all over. which line do i have to change?
ut my code is reading data from the file. but why is it only displaying the same value?
yea this is what i got--------------------Configuration: <Default>--------------------
1280
1280
1280
1280
1280
1280
1280
1280
1280
i read the values into the array but its displaying each value 4 times. thats my only problem
I want to store all the values from the text file into the array.
int [] distance = new int [10];//array of size 10
int dist=in.nextInt();//read first value from file
while (dist!=0){//while value is not equal to 0 do
for(int...
ok i made some changes and now the program is reading all the values but it is displaying each value 4 times.ow can i fix it so that it only displays each value once?
int [] distance = new int...
ok i added some printlsn and i made some progress. not too sure how to format the code like you said.
but the program is now reading all the data and displaying it. however after it is displayed...
the file im reading from consists of several integers. the last value is zero. so im trying to read the values. zero is the end of file value so i must stop reading the data when a zero is encountered
public static void main (String [] args) throws IOException{
Scanner in = new Scanner(new FileReader("distances.txt"));
int [] distance = new int [100];
int dist=in.nextInt();
while...
this is what i tried but its only displaying the same number.
public static void main (String [] args) throws IOException{
Scanner in = new Scanner(new FileReader("distances.txt"));
...
I dont know what is an array list. We just did basic arrays in class so i dont think i can use that.
yes the numbers represent fueling stations from Earth to the destination. Is there a way to read those values into an array without knowing the size of the array
--- Update ---
this does...
A spaceship has to travel a distance of 1500 miles away from earth. The spaceship can only travel 220 miles before it needs to refuel. It is fueled before it leaves earth and there are several...
had to submit it already. We can use those Array.toString yet since the lecturer did not teach it and does not want us implementing things he did not teach.
lol.What do i have to do to make post #4 work?
is this close? im getting an infinite loop then my program crashed.
System.out.printf("Enter a number:");
int n = in.nextInt();
System.out.printf("Enter a value for m:");
int m =...