Sort integers in array/list then print them out in particular order in Java? -


here code:

/* package whatever; // don't place package name! */  import java.util.*; import java.lang.*; import java.io.*;  /* name of class has "main" if class public. */ class ideone {     public static void main (string[] args) throws java.lang.exception     {         int[] numbers = {9, 5};          if (numbers[0] > numbers[1]){             system.out.print(arrays.tostring(numbers));         }else if (numbers[1] > numbers[0]){             system.out.print(arrays.tostring(numbers));         }     } } 

so far have code grabs numbers , prints them out. if statement. there way can below:

if (numbers[0] > numbers[1]){                 system.out.print(arrays.tostring(numbers(1, 0));             }else if (numbers[1] > numbers[0]){                 system.out.print(arrays.tostring(numbers(1, 0));             } 

where 0 , 1 positions in array. system.out.print(numbers[0]); valid syntax or how can doing avoiding converting tostring() stage

thanks

p.s. new java hence simpleness, note: trying not sure built-in functions .sort() because defeats point of exercise.

you can try this:

arrays.sort(numbers); system.out.println(arrays.tostring(numbers)); 

or this:

public static void exchangesort ( int [ ] num ) {      int i, j, temp;      ( = 0; < num.length - 1; ++ ) {           ( j = + 1; j < num.length; j ++ ){                if( num[ ] < num[ j ] ){                        temp = num[ ];                         num[ ] = num[ j ];                        num[ j ] = temp;                  }                      }      } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -