i cant make it work

June 28, 2012 at 05:32:00
Specs: Windows XP
package JAVA;
import java.util.Scanner;
public class FIRST
{
static Scanner input = new Scanner(System.in);
public static void main(String[] args)

{
int ctr, sum=0;
int[] array = new int[10];

System.out.println("PLEASE ENTER 10 NUMBERS:");
for(ctr=0;ctr<10;ctr++)
{
int x=input.nextInt();
array[ctr]= x;
sum=sum+x;
}

System.out.println("sum = "+sum);


int i, t=0;

for(i = 0; i<=10; i++)
{
int j;

for(j = 1; j <(10-i); j++)
{
if(array[j-1]>array[j])
{
t =array[j-1];
array[j-1]=array[j];
array[j]=t;
}
}
}

System.out.println("smallest number = "+ t);

System.out.println("largest number = "+ array[j] );
}
}


*****HOW COME IT DOESN'T WORK***** HELP!!!!!


See More: i cant make it work

Report •


#1
June 28, 2012 at 18:35:57
Since the array is now sorted, don't you just want to "output" array[0] for smallest and array[9] for largest? Endpoints might need tweaked also...

Report •
Related Solutions


Ask Question