Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Inputing file (.txt) and finding the highest number in the file

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Inputing file (.txt) and finding the highest number in the file

    I have attached my src folder. It contains the .java and the in.txt

    the txt file is in this format

    number of users
    how many numbers are listed for user1 (ex 4)
    user1 number 1
    user1 number 2
    user1 number 3
    user1 number 4
    how many numbers are listed for user 2 (ex 3)
    user2 number 1
    user2 number 2
    user2 number 3

    and so on.

    I am trying to calculate the max number for each user.

    Please help, i am getting errors after adding an if statement.

    I believe the problem is around the if statement

    Scanner inputFile = new Scanner(file);
    		int numusers = inputFile.nextInt();	
    		int counter2 = 0;
    		System.out.println(numusers);
    		while(numusers>counter2)
    				{
    				int numrates = inputFile.nextInt();		// gets number of rates for user
    				int[] a = new int[numrates];	
    				System.out.println("This is the numrates: "+ numrates);
    				int counter = 0;
    							while(counter<numrates) // goes until counter hits number of rates specified
    							{
    							int maximum = -1;
    							for (int i = 0; i <= a.length; i++)  //calculates the max
    								{
    									{ 	a[i] = inputFile.nextInt();
    										if (a[i] > maximum) {
    										maximum = a[i]; // writes number to maximum
    										}
    									}
    								if(i==a.length)  // when counter (i) hits the last digit, this writes the maximum value found
    								{	System.out.println("This is the max: "+ maximum);}
    								}
    							counter++; //counts against the number of rates per user
     
    							}
    				counter2++; //counts the number of users that program has ran through
    				}
    			        inputFile.close();
     
    	}
    }
    Attached Files Attached Files
    Last edited by alf; March 14th, 2010 at 10:53 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Inputing file (.txt) and finding the highest number in the file

    I recommend posting a short snippet of your code directly into your posted text (surrounded by the code tags), I suggest this because many including myself may be hesitant to download and open a zip file.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Inputing file (.txt) and finding the highest number in the file

    edited

    site should allow for .txt or .java files to be uploaded

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Inputing file (.txt) and finding the highest number in the file

    bump.. please help!

Similar Threads

  1. How to find location of ipaddress using Java
    By tej in forum Java Networking
    Replies: 8
    Last Post: September 8th, 2012, 06:05 AM
  2. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM
  3. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM
  4. Need Help - Factoring & Prime Finding Code
    By prodigytoast in forum Algorithms & Recursion
    Replies: 5
    Last Post: November 5th, 2009, 07:38 AM
  5. Replies: 13
    Last Post: May 6th, 2009, 09:27 AM