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

Thread: Unsatisfied

  1. #1
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Angry Unsatisfied

    Hey, guys i am really unsatisfied with my program concerning it's ouput:Can you help me in compiling and get the satisfied results
    import java.util.*;
    class assignmentone 
    {
    	public static void main(String[] args) 
    	{
    		Scanner console = new Scanner(System.in);
     
    		double num1,num2,num3,num4,num5,sum,average;
     
    		System.out.println("Enter five decimal numbers:");
    		num1 = console.nextDouble();
            num2 = console.nextDouble();
            num3 = console.nextDouble();
            num4 = console.nextDouble();
            num5 = console.nextDouble();
     
    		sum = num1 + num2 + num3 + num4 + num5;
    		average = sum/5;
     
     System.out.println("Number roundedoff is" + (int) (num1 + 0.5) +
    			                                       (int) (num2 + 0.5) +                  
                                                       (int) (num3 + 0.5) +
                                                       (int) (num4 + 0.5) +
                                                       (int) (num5 + 0.5)  +
    			                                       (int) (sum +  0.5) +
    			                                       (int)  (average + 0.5) );  
             System.out.println("The total is = " + sum +" and the average of the total number is = " + average);
     
    	}
    }
    Last edited by helloworld922; February 4th, 2010 at 08:22 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Unsatisfied

    not without you telling us what kind of results you want.

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: Unsatisfied

    exactly.. you should post a little bit more informative question ..

    have a look at this How To Ask Questions The Smart Way

  4. #4
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Re: Unsatisfied

    well here is the questions guys and forgive me coz there will be alot more of them kind coming to this forum.
    the program should does the following
    -prompt the user to input five decimal numbers representing the scores
    -prints the five decimal numbers
    -converts each decimal number to the nearest integer
    -adds the five integers
    -prints the sum and average of the five integers

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Unsatisfied

    Math.round() will round the number for you. I'm assuming that the average is going to be displayed in decimal form? If not, just remove the cast to double from the println command.

    int sum = (int) (Math.round(num1) + Math.round(num2) +  Math.round(num3) + Math.round(num4) + Math.round(num5)); // because Math.round() converts to a long
    System.out.println("Integer sum is " + sum);
    System.out.println("Integer average is " + (double) sum / 5);

  6. #6
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Unsatisfied

    You can use this code to print as desired.


    import java.util.*;
    class assignmentone
    {
    public static void main(String[] args)
    {
    Scanner console = new Scanner(System.in);

    double num1,num2,num3,num4,num5;
    long sum,average;

    System.out.println("Enter five decimal numbers:");
    num1 = console.nextDouble();
    num2 = console.nextDouble();
    num3 = console.nextDouble();
    num4 = console.nextDouble();
    num5 = console.nextDouble();

    sum = Math.round(num1) + Math.round(num2) + Math.round(num3) + Math.round(num4) + Math.round(num5);
    average = sum/5;


    System.out.println("First Number"+num1);
    System.out.println("First Number"+num2);
    System.out.println("First Number"+num3);
    System.out.println("First Number"+num4);
    System.out.println("First Number"+num5);


    System.out.println("The total is = " + sum +" and the average of the total number is = " + average);

    }
    }

  7. #7
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up Re: Unsatisfied

    HEY GUYS THANKS FOR THE HELP.IT SEEMS YOUR ASSISTANCE IS JUST WHAT THE DOCTOR ORDERED. THANKS AGAIN.