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 2 of 2

Thread: Int not adding up right.

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Int not adding up right.

    		int wordpercent = ((count/totalwords)*100);
    					JOptionPane.showMessageDialog(null, "Count: " + count);
    					JOptionPane.showMessageDialog(null, "Words: " + totalwords);
    					JOptionPane.showMessageDialog(null, "Character Count: " + length);
    					JOptionPane.showMessageDialog(null, previousletter);
    					JOptionPane.showMessageDialog(null, nextletter );
    					JOptionPane.showMessageDialog(null, "Your word makes up " + wordpercent + "% of the document");

    This is the last part of my program. The program lets you select a text file, type out a word, and then finds how many times that word is in the document as well as how many characters and words are in the total document. I would also like it to show how much of a percent of the total document the typed in word makes. Everything works except for the wordpercent variable. It shows up as 0, even though the count and totalwords variables will have the correct numbers. If I flip it around and do (totalwords/count) I get a number as well, although the number isn't correct. Any ideas? An example would be, count shows up as 26 and totalwords shows as 340, then wordpercent shows up as 0.


  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Int not adding up right.

    Ah figured it out, obvious mistake of using an int when I should have used a double.

Similar Threads

  1. Java program to do Matrix operation
    By saladfingers73 in forum Collections and Generics
    Replies: 5
    Last Post: March 7th, 2012, 09:17 AM
  2. Need Help Adding Functionality to GUI!
    By Black Balloon in forum AWT / Java Swing
    Replies: 1
    Last Post: August 29th, 2011, 07:16 AM
  3. Help adding non repetition.
    By arkaneraven in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 15th, 2011, 09:31 PM
  4. Adding Big Numbers
    By hoiberg in forum Java Theory & Questions
    Replies: 5
    Last Post: December 16th, 2010, 08:44 AM
  5. adding up odd and even numbers
    By darlinho in forum What's Wrong With My Code?
    Replies: 10
    Last Post: September 30th, 2010, 03:28 PM