Results 1 to 7 of 7
Thread: input array
- 07-14-2011, 08:33 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
input array
Hello!
this is my program
Array.txt.Java Code:import java.util.*; public class InputArray { public static void main (String[] args){ Scanner in = new Scanner("D:\\Docs\\temp\\4.txt"); String[] days = new String[100]; int n = 0;// Current number of values in days. while (in.hasNext()){ if (n>= days.length){ System.err.println("Too much data!"); System.exit(1); } days[n] = in.nextLine(); n++; System.out.println(""+days[n]); } //... Now do something with the days! } }
why in ConsoleJava Code:"Su" "Mo" "Tu" "We" "Th" "Fr" "Sa"
Please help me. i need help.Java Code:null
- 07-14-2011, 08:55 AM #2
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
you are incrementing your index value before you are printing the array value. So you are inserting into days[n] and printing days[n+1] which is empty. put your n++ statement below the println and see what happens.
- 07-14-2011, 09:01 AM #3
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
ConsoleJava Code:days[n] = in.nextLine(); System.out.println(""+days[n]); n++;
((Java Code:D:\Docs\temp\4.txt
- 07-14-2011, 09:14 AM #4
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
you are passing a string to the scanner, you need to pass a file
- 07-14-2011, 09:21 AM #5
Member
- Join Date
- Jul 2011
- Posts
- 2
- Rep Power
- 0
you should do like this
File file = new File("D:\\Docs\\temp\\4.txt");
Scanner in = new Scanner(file);
- 07-14-2011, 09:24 AM #6
And you need to decide whether that file is named Array.txt or 4.txt
db
- 07-14-2011, 10:32 AM #7
Member
- Join Date
- Jul 2011
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Help with validating input into an array
By kcoltharp in forum New To JavaReplies: 1Last Post: 02-25-2011, 09:05 AM -
Input skips on array
By kryptonian03 in forum New To JavaReplies: 4Last Post: 12-13-2010, 12:48 AM -
Array Input
By Rose88 in forum New To JavaReplies: 2Last Post: 04-19-2009, 10:39 PM -
input placed in array
By smilejava in forum New To JavaReplies: 5Last Post: 11-12-2007, 07:29 AM -
input placed in array
By smilejava in forum New To JavaReplies: 1Last Post: 11-05-2007, 12:32 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks