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

Thread: help please i don't understand why the count is not adding .

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help please i don't understand why the count is not adding .

    i am trying to make a program that get input value 1-200 from user.
    however i would like to make the program to show warning if the input number is not within the range of 1-200. in the end i would like to show the amount of number according to its interval (i.e less 50, 51-100 and so on)


    import java.util.Scanner;
     
    class test {
    public static void main (String[] args)
    {
    int number[]= new int[5];
    int number2[]= new int[5];
    int a=0,b=0,c=0,d=0,i=0;
    int a2=0,b2=0,c2=0,d2=0,j=0;
    int a3,b3,c3,d3;
    Scanner input = new Scanner(System.in);
     
    for (i=0;i<5;i++)
    { System.out.println("Enter Number between 1-200 :");
    number[i] = input.nextInt();
    if (number[i] <1 || number[i] > 200)
    {
    for (j=0;j<1;j++)
    {
    System.out.println("Number is invalid, please Enter a New number");
    number2[j] = input.nextInt();
    j++;
    if (number2[j] >=1 && number2[j] <50)
    a2++;
    else if (number2[j] >=50 && number2[j] <101)
    b2++;
    else if (number2[j] >= 101 && number2[j] <151)
    c2++;
    else if (number2[j] >= 151 && number2[j] <201)
    d2++;
    }
     
    }
    if (number[i] >=1 && number[i] <50)
    a++;
    else if (number[i] >=50 && number[i] <101)
    b++;
    else if (number[i] >= 101 && number[i] <151)
    c++;
    else if (number[i] >= 151 && number[i] <201)
    d++;
    }
    a3 = a +a2;
    b3 = b +b2;
    c3 = c +c2;
    d3 = d +d2;
    System.out.println("Less than 50 :" +a3 );
    System.out.println("50-100 :" +b3);
    System.out.println("101-150 :" +c3 );
    System.out.println("151-200 :" +d3);
     
    }
    }


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: help please i don't understand why the count is not adding .

    What are you having problems with?
    As far as I see you already did that yourself. Are you getting any kinds of errors or unexpected behavior?

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help please i don't understand why the count is not adding .

    Quote Originally Posted by Cornix View Post
    What are you having problems with?
    As far as I see you already did that yourself. Are you getting any kinds of errors or unexpected behavior?
    the value didn't add. but i am trying now using method instead. but i have so many errors. i have no idea what to do.

     
        import java.util.Scanner;
        class JavaStatistic {
        public static void main (String[] args){
        int i=0;
        int number[]= new int[5];
        Scanner input = new Scanner(System.in);
        for (i=0;i<5;i++){
        System.out.println("Enter Number between 1-200 :");
        number[i] = input.nextInt();
        if (number[i] <1 || number[i] > 200){
        System.out.println("Number is invalid, please Enter a New number");
        i--;
        }
        else{
        number[1] = displayStatistics(int[] input)
        }
        int statistics[] = displayStatistics(number);
        System.out.println("Less than 50 :" +statistics[0]);
        System.out.println("50-100 :" +statistics[1]);
        System.out.println("101-150 :" +statistics[2]);
        System.out.println("151-200 :" +statistics[3]);
        }
        }
        void displayStatistics(int [] input ){
        int count[] ={0,0,0,0};
        { //this loop will be entered when the input is in the correct range{
        int i;
        if (number[i] >=1 && number[i] <50)
        count[0]++;
        else if (number[i] >=50 && number[i] <101)
        count[1]++;
        else if (number[i] >= 101 && number[i] <151)
        count[2]++;
        else if (number[i] >= 151 && number[i] <201)
        count[3]++;
        System.out.println("Enter Number between 1-200 :");
        return count;
        }
        }
        }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: help please i don't understand why the count is not adding .

    Post the errors you want help with and the code that goes with the errors. Please post properly indented code. Code with lines all aligned at column zero is hard to read.

Similar Threads

  1. I don't understand this. Please help...
    By javaman1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 20th, 2014, 04:32 AM
  2. I don't understand what's wrong in my programme
    By si3012 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 16th, 2013, 07:58 AM
  3. Don't understand void methods, need help!
    By alex067 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 9th, 2012, 07:02 AM
  4. Simply don't understand minimax...
    By Herah in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 13th, 2011, 12:45 PM
  5. I don't understand what I'm supposed to do
    By dmcettrick in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 11th, 2011, 09:34 AM