Results 1 to 6 of 6
  1. #1
    qema is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Unhappy why my coding cannot give the correct answer?

    somebody help me please..here my coding

    import java.util.Scanner;
    public class SumNumbers4 {
    public static void main(String[] args){

    Scanner scanner = new Scanner(System.in);

    System.out.println("How many number?");
    int numNumber = scanner.nextInt();

    int data = 0;
    int max = data;
    int min = data;
    int sum = 0;
    for(int i = 1;i<= numNumber ; i++) {

    System.out.println("Please input number" + i + ":");
    int number = scanner.nextInt();

    sum += number;

    }
    System.out.println("Sum of the number is" + sum);

    double average = sum/numNumber;
    System.out.println(" The average is" + average);

    if (data> max){
    max = data;
    }

    else if (data < min){
    min = data;
    }

    else if (data >= 0 & data < max){
    min = data;
    }

    else if (data<= 0 & data> min){
    max = data;
    }

    System.out.println("The largest number is" + max);
    System.out.println("The smallest number is" + min);
    }
    }
    :(

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Thanks for posting that. That's some really nice code.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default hhhmmm...

    Remember... the most information you can provide will result in better and more accurate help. Just posting code and saying "code is giving wrong output" does not help diagnose the problem with your code. Imagine taking your car to the mechanics and saying "it doesn't work". How is he going to fix the car with that information?
    I magine your output is zero for both min & max. That is because they were initially assigned zero and never were given any other value (check your code).

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    qema is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default ...

    Quote Originally Posted by CJSLMAN View Post
    Remember... the most information you can provide will result in better and more accurate help. Just posting code and saying "code is giving wrong output" does not help diagnose the problem with your code. Imagine taking your car to the mechanics and saying "it doesn't work". How is he going to fix the car with that information?
    I magine your output is zero for both min & max. That is because they were initially assigned zero and never were given any other value (check your code).

    Luck,
    CJSL
    thanx for ur rep. i'm the beginner user n i'm still learning java coding

  5. #5
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    6

    Default

    Hi,
    I didnt understand the intension of this code. You are comparing data with max and min, which again have the same value as data.

    Can you tell us what actually you are trying to do and paste any output/ error you are getting, so that we can help you better.
    To finish sooner, take your own time....
    Nivedithaaaa

  6. #6
    chrono25 is offline Member
    Join Date
    Feb 2009
    Posts
    10
    Rep Power
    0

    Default

    Yeah i don't quite get it either, seems as if it was some kind of calculator thingie madoo but we need more data in order to accurately comment on it :(

Similar Threads

  1. Repeat while answer yes - do while loop
    By AJ2009 in forum New To Java
    Replies: 1
    Last Post: 01-10-2009, 06:19 PM
  2. Why is the answer not coming out
    By anonymous18 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 03:10 AM
  3. Replies: 3
    Last Post: 11-02-2008, 01:29 AM
  4. Plz answer this question ...
    By raghu2114 in forum Advanced Java
    Replies: 2
    Last Post: 09-19-2008, 06:36 PM
  5. guss which is correct answer
    By abhinav_jain09 in forum Java Applets
    Replies: 4
    Last Post: 09-19-2008, 02:39 AM

Posting Permissions

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