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

Thread: Need some help

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Need some help

    Hey there, I am extremely new to java and was wanting some help on this bug I am getting.
    My code is as follows:
    import java.util.Scanner;
    public class bavg{
    	public static void main (String args[]){
    		Scanner keyboard=new Scanner(System.in);
    		System.out.println("Enter the amount of at-bats.");
    		int ab=keyboard.nextInt();
    		System.out.println("Now, enter the amount of hits.");
    		int hits=keyboard.nextInt();
    		int avg=(hits/ab);
    		System.out.println("Your batting average is "+avg+".");
    	}
    }
    But whenever I run the program, no matter what I do, I get my average is 0.0
    Anyone have any suggestions?

    Again I am very new to java so I apologize in advance for any silly mistakes.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help

    I tried turning the int "avg" into a double to see if that did anything, but it didn't help.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help

    This is now fixed ^_^