Results 1 to 6 of 6
  1. #1
    Raian is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default 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());
    }
    }
    }

  2. #2
    erakhman is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default

    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);
    		}
    	}
    }

  3. #3
    Raian is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    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.

  4. #4
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default

    I ran it and it worked
    ..

    is that all . u want to improve ur programming ? i think its not enough ..

  5. #5
    Raian is offline Member
    Join Date
    May 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by programmer_007 View Post
    ..

    is that all . u want to improve ur programming ? i think its not enough ..
    yea i know that's is not good enough to improve my programming? I'm really new to this, but i will try..thanks

  6. #6
    erakhman is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Raian View Post
    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.
    You're welcome :)

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  2. Replies: 1
    Last Post: 05-31-2009, 06:48 PM
  3. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  4. Replies: 16
    Last Post: 05-28-2009, 03:41 PM
  5. Java programming help
    By mukul9999 in forum New To Java
    Replies: 2
    Last Post: 04-30-2009, 01:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •