Total members 11895 |It is currently Mon Dec 23, 2024 3:56 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I have been trying to figure out this assignment for like two days but i seem to not be able to figure out the right code for it. I'm really having trouble with the if and else statement. So if you can please help me, it will be a life saver.

The purpose of this assignment is have the user input 3 numbers for a,b,c. then the output should be in non-descending order.

Code:

import java
.util.Scanner;

 public class NondescendingOrder {
     public static void main (String[] args) {

         // declares variables
         int a,b,c;
         Scanner input= new Scanner (System.in);

         // ask user for input
         System.out.print("Please enter three numbers separated by space: ");

         // read and store the input
         a= input.nextInt();
         b= input.nextInt();
         c= input.nextInt();

         //output of input
         System.out.println ("Input 1= " +a);
         System.out.println ("Input 2= " +b);
         System.out.println ("Input 3= " +c);

         // if and else statement

        if (a<b) {
                if (b<c)
                System.out.println("The order is: "+a+" "+b+" "+c);
                    else
                    System
.out.println("The order is: "+a+" "+c+" "+b);

        }
        else if (b<a){
                if (a<c)
                System.out.println("The order is: "+b+" "+a+" "+);
                    else
                    System
.out.println("The order is: "+b+" "+c+" "+a  );
        }

        else if (c<a){
                if (b<a)
                System.out.println("The order is: "+c+" "+a+" "+b);
                    else
                    System
.out.println("The order is: "+c+" "+b+" "+a);

        }


    }
}
 





Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

Code:


  if (a<=b) {
            if (b<c)
            System.out.println("The order is: "+a+" "+b+" "+c);
                else
               System.out.println("The order is: "+a+" "+c+" "+b);

      }
      else if (a<=c){
            System.out.println("The order is: "+b+" "+a+" "+c );
      }
      else {
            if (b<c)
            System.out.println("The order is: "+b+" "+c+" "+a);
               else
               System.out.println("The order is: "+c+" "+b+" "+a);

      }



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Input three numbers and then sort non descending order
 SQL ORDER BY     -  
 Difference in order between HashSet and ArrayList     -  
 How to display WooCommerce customer order details     -  
 How to change the default order on forums from ascending to     -  
 Return an array with elements in reverse order     -  
 rank order filter effects on image     -  
 SELECT-Group by and Order by,Having Clause,count(),Joins     -  
 Input-Output Operations     -  
 getting a full line input     -  
 Only numeric input in JTextField     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com