Results 1 to 6 of 6
- 05-23-2010, 05:54 AM #1
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Can anyone help me with this java programming please???
Hello everyone,
My name is Raian. I'm really new to java programming. I don't have any good background with programming. Really, I'm really bad at it. Can you guys help me with this please?
This is the project:
Instead of writing a separate line to read each word (or number / item) in your text file use a while loop and have the ending condition be the false for the next statement.
I am having problem with the while loop for the text file. How can i use a while loop and have the ending condition be the false for the next statement---without using System.out.println(myScan.hasNext());
Much help is appreciated. Thanks.
Here is i have so far.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Project7 {
public static void main(String[] args) throws FileNotFoundException {
File file = new File ("word.txt");
Scanner myScan = new Scanner (file);
String fil = myScan.next();
System.out.println(fil);
System.out.println(myScan.next());
System.out.println(myScan.next());
System.out.println(myScan.hasNext());
while(myScan.hasNext()){
System.out.println( myScan.next());
}
}
}
- 05-23-2010, 06:37 AM #2
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
try this code :
Java Code:import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Project7 { public static void main(String[] args) throws FileNotFoundException { File file = new File ("word.txt"); Scanner myScan = new Scanner (file); /*String fil = myScan.next(); System.out.println(fil); System.out.println(myScan.next()); System.out.println(myScan.next()); System.out.println(myScan.hasNext());*/ while(myScan.hasNext()){ //System.out.println( myScan.next()); String fil = myScan.next(); System.out.println(fil); } } }
- 05-23-2010, 07:35 AM #3
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Thank you so much Erakhman. I ran it and it worked. You helped me clear it up. Once again, I'm really appreciated for your help. I'm just trying to learn something new, but programming is so hard.
- 05-23-2010, 10:09 AM #4
..I ran it and it worked
is that all . u want to improve ur programming ? i think its not enough ..
- 05-23-2010, 10:12 AM #5
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
- 05-23-2010, 11:33 AM #6
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 10:57 PM -
E:\IT 215 Java Programming\Inventory.java:211: reached end of file while parsing
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 06:48 PM -
E:\IT 215 Java Programming\GUI1.java:125: class, interface, or enum expected
By tlouvierre in forum New To JavaReplies: 1Last Post: 05-31-2009, 02:17 PM -
E:\IT 215 Java Programming\Inventory.java:36: class, interface, or enum expected
By tlouvierre in forum Advanced JavaReplies: 16Last Post: 05-28-2009, 03:41 PM -
Java programming help
By mukul9999 in forum New To JavaReplies: 2Last Post: 04-30-2009, 01:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks