Results 1 to 4 of 4

Thread: No Output (?)

  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default No Output (?)

    Hello All.
    I am running this code in Eclipse. I enter a value (2) for newNum, but nothing else happens. Can someone tell me why? Thank you

    Java Code:
    import java.util.*;
    
    public class Ex5_14  
    {
    	static Scanner console = new Scanner(System.in);
    	
    	public static void main(String[] args)
    	{
    		int i;
    		int newNum;
    		int average;
    		int sum;
    		
    		sum = 0;
    		
    		for (i = 0; i < 5; i++)
    		{
    			newNum = console.nextInt();
    			sum = sum + newNum;
    		}
    
    		average = sum / 5;
    		System.out.println("The sum is " + sum);
    		System.out.println("The average is " + average);
    		
    	}
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    12

    Default

    but nothing else happens
    What do you expect to happen? Step through the code one line at a time from the perspective of the computer...what will happen after you are prompted for and enter the first number?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default

    Quote Originally Posted by doWhile View Post
    What do you expect to happen? Step through the code one line at a time from the perspective of the computer...what will happen after you are prompted for and enter the first number?
    That code doesn't prompt the user for anything; the user is just supposed to start typing; very user friendly indeed ;-)

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    12

    Default

    That code doesn't prompt the user for anything; the user is just supposed to start typing; very user friendly indeed ;-)
    Indeed...:) (I was using the word prompt more as a hint than anything else)

Similar Threads

  1. Replies: 0
    Last Post: 09-30-2010, 08:16 PM
  2. Why do I get this output?
    By Allspark in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 08:07 AM
  3. Need help with output
    By cedric11 in forum New To Java
    Replies: 4
    Last Post: 11-30-2009, 01:09 PM
  4. Can anyone tell me how this output?
    By vysh in forum Advanced Java
    Replies: 16
    Last Post: 05-10-2009, 08:32 PM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •