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

Thread: Java program to find which of the three is the highest number, which of the three is the lowest one and to show how many odd and how many even number

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

    Default Java program to find which of the three is the highest number, which of the three is the lowest one and to show how many odd and how many even number

    just having some problems with this program, the program should compute the sum of the three numbers,
    and i have to display the average of those three.,im done and im fine with it..

    the problem is..
    to display which of the three is the highest number, which of the three is the lowest one and to show how many odd , and how many even number that have been keyed in.

    can anyone help with this simple algorithm?

    this is the syntax

    import java.io.*;
     
     public class threeNumbers
     
      {
     
       private static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
     
        public  static void main(String[] args)throws IOException
     
         {
     
           String number1,number2,number3; 
           int num1,num2,num3,result,average;
     
            System.out.print("Enter a number : ");
        number1=br.readLine();
        num1=Integer.parseInt(number1);
     
        System.out.print("Enter the second number : ");
        number2=br.readLine();
        num2=Integer.parseInt(number2);
     
        System.out.print("Enter the third number : ");
        number3=br.readLine();
        num3=Ingteger.parseInt(number3);
     
        result=num1+num2+num3;
        average=result/3;
     
        System.out.println("The result for the three numbers is : " +result);
        System.out.println("The average for the three numbers is : " +average);
     
          }
     
       }
    // I dont have any more idea on what kind of algorith should i make to display that problem
    display how many three numbers
    Last edited by Deep_4; November 7th, 2012 at 11:22 PM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: cant solve this one.. Selection structue problem and something more .. Help tnx

    Just check them against each other to compare sizes then print out the results. Also just count how many are even you can check with %2 == 0

    Chris

  3. #3
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: cant solve this one.. Selection structue problem and something more .. Help tnx

    here's my code:

     
    /**
     *
     * @author Truffy
     */
    import java.io.*;
     
     public class threeNumbers
     
      {
     
       private static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
     
        public  static void main(String[] args)throws IOException
     
         {
     
           String number1,number2,number3, odd, even; 
           int num1,num2,num3,result,average,highest, lowest,b;
     
            System.out.print("Enter a number : ");
        number1=br.readLine();
        num1=Integer.parseInt(number1);
     
        System.out.print("Enter the second number : ");
        number2=br.readLine();
        num2=Integer.parseInt(number2);
     
        System.out.print("Enter the third number : ");
        number3=br.readLine();
        num3=Integer.parseInt(number3);
     
        //det the odd or even
        if(num1%2 == 1){
            System.out.println("odd number :" +num1);
        }else{ 
            System.out.println("even3 number :" +num1);}
     
            if(num2 % 2 == 1){
            System.out.println("odd number :" +num2);
        }else {System.out.println("even number :" +num2);}
     
        if(num3 % 2 == 1){
            System.out.println("odd number :" +num3);
        }else{System.out.println("even number :" +num3);}
     
       //determine the highest number 
       if(num1>num2){
           if(num1>num3){
               System.out.println("Highest number  is :" +num1);
           }else
               System.out.println("Highest number  is :" +num3);
       }else{
            if(num2>num3){
                System.out.println("Highest number  is :" +num2);
            }else{
                System.out.println("Highest number  is :" +num3);
            }
       }
     
        //determine the lowest number
         if(num1<num2){
           if(num1<num3){
               System.out.println("Lowest number  is :" +num1);
           }else
               System.out.println("Lowest number  is :" +num3);
       }else{
            if(num2<num3){
                System.out.println("Lowest number  is :" +num2);
            }else{
                System.out.println("Lowest number  is :" +num3);
            }
       }
     
     
     
     
        result=num1+num2+num3;
        average=result/3;
     
     
        System.out.println("The result for the three numbers is : " +result);
        System.out.println("The average for the three numbers is : " +average);
     
     
          }
     
       }


    hope it helps.

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

    Smile Re: cant solve this one.. Selection structue problem and something more .. Help tnx

    tnx chris!and truffy! i just forgot how to use mod and how to get a number's remainder
    hehe

    anyway tnx again!!

  5. #5
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: cant solve this one.. Selection structue problem and something more .. Help tnx

    Quote Originally Posted by chronoz13 View Post
    tnx chris!and truffy! i just forgot how to use mod and how to get a number's remainder
    hehe

    anyway tnx again!!
    no problem.

    if you are satisfied pls mark your thread as solved. )

Similar Threads

  1. Java error "java.lang.StackOverflowError"
    By sanatkumar in forum Exceptions
    Replies: 2
    Last Post: July 7th, 2009, 02:40 PM
  2. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM