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: Sums of nextInt for file input

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Sums of nextInt for file input

    How can I modify this part of my code so that "token" would be the previous number the program input from the text file and the current number? For example, there is 2 number inside the text file, the 1st = 2 and the 2nd =4 , how can I make "token" be the sum of these two? Thanks
               while(inFile.hasNextInt())  
               {  
               token =+ inFile.nextInt();  
               System.out.println(token);  
               winCounter++;  
               }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Sums of nextInt for file input

    What's wrong with the code you are currently showing?

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: Sums of nextInt for file input

    "token" will be the last integer that the hasNextInt() find instead of the sum of the previous one and the current one. What I'm trying to do is make "token" be the sum of all the number the hasNextInt() find

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Sums of nextInt for file input

    Perhaps you want to change =+ to +=.

  5. The Following User Says Thank You to curmudgeon For This Useful Post:

    maple1100 (December 27th, 2012)

Similar Threads

  1. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  2. Replies: 2
    Last Post: November 2nd, 2011, 05:22 AM
  3. how to get value path file from jsp form- input type file
    By meeGoreng in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: October 4th, 2011, 12:05 AM
  4. nextint() Method !
    By M7MD in forum Object Oriented Programming
    Replies: 11
    Last Post: October 27th, 2010, 11:47 AM
  5. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM