Results 1 to 3 of 3
  1. #1
    sirdonclemo is offline Member
    Join Date
    Aug 2010
    Location
    US
    Posts
    4
    Rep Power
    0

    Default What Method and loops to get the distance

    L 0 400 500 650 700
    B 400 0 300 550 320
    P 500 300 0 700 120
    A 650 550 700 780
    A 700 320 120 780 0

    above is a text file and is the distance from different location. for example the distance from L to L is 0, the distance from L to B is 400miles and the distance from B to L is same 400miles, the distance from B to P is 300miles.


    i know am suppose to create an array for this but am confuse cos i want to use my array with the scanner class

    Java Code:
    import java.util.Scanner;
    import java.io.File;
    import java.io.*;
    
    
          public class Distance
          {
              public static void main (String[]args) throws FileNotFoundException 
              {
                  //Scanner scan = new Scanner (System.in);
                  // this reads from the keyboard that is the system.in
                  File myfile = new File ("naija.txt");
                  Scanner scan = new Scanner (myfile);
                  String wrd = scan.next ();
                  System.out.println (wrd);
                  while (scan.hasNextLong()) {
              long aLong = scan.nextLong();
              // this loop prints the first stuff
              System.out.println (scan.next());
    
                }
            }
        }
    this is the code i have written so far.
    Last edited by Fubarable; 09-05-2010 at 04:10 AM. Reason: Moderator Edit: Code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sirdonclemo View Post
    i know am suppose to create an array for this but am confuse cos i want to use my array with the scanner class
    > ....

    this is the code i have written so far.
    Yes, you are right -- your next step is to create a two-dimensional int array, and try to use it and fill it with data using your Scanner. Give it a shot, you've nothing to lose, and then if it doesn't work, post your attempt here with any error messages.

    Also, you'll want to use code tags when posting code (I've added them to your post above) so your code will retain its formatting and be readable. Please see the link in my signature to find out how to do this.

    Best of luck and welcome to the forum!

  3. #3
    sirdonclemo is offline Member
    Join Date
    Aug 2010
    Location
    US
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 08-23-2010, 03:06 PM
  2. Replies: 2
    Last Post: 04-14-2009, 11:01 PM
  3. Replies: 0
    Last Post: 04-02-2009, 10:00 PM
  4. Replies: 11
    Last Post: 04-01-2009, 04:43 AM
  5. Calculate X and Y given starting angle and distance
    By nidhirastogi in forum Java 2D
    Replies: 5
    Last Post: 08-18-2008, 11:24 PM

Posting Permissions

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