QuestionAsk Questions?

I am trying to get this into reverse order. Does anybody know how

import java.util.*;

public class Smallest {

public static void main(String[] args) { Scanner kybd = new Scanner(System.in); //create array to hold 10 integers int[] numbers = new int[10]; System.out.println("Enter 10 integers: "); //read 10 integers into array for (int i = 0; i < numbers.length; i++) { numbers[i] = kybd.nextInt(); } //initialise largest value and location to first array element int smallest = numbers[0]; int SmallestLocation = 0; //step through each array location for (int i = 1; i < numbers.length; i++) { //check if arra<y location is new largest if (numbers[i] < smallest) { smallest = numbers[i]; SmallestLocation = i; }

//output value and location of largest element System.out.println("Smallest value: " + smallest); System.out.println("Location of largest value: " + SmallestLocation);

}

}

}

View Answers

December 7, 2011 at 3:00 PM

import java.util.*; public class Smallest { public static void main(String[] args) { Scanner kybd = new Scanner(System.in); int[] numbers = new int[4]; System.out.println("Enter 10 integers: "); for (int i = 0; i < numbers.length; i++) { numbers[i] = kybd.nextInt(); } int smallest = numbers[0]; int SmallestLocation = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < smallest) { smallest = numbers[i]; SmallestLocation = i; } } System.out.println("Smallest value: " + smallest); System.out.println("Location of largest value: " + SmallestLocation); System.out.println("Numbers in reverse order: "); for (int i = numbers.length-1; i >=0; i--) { System.out.println(numbers[i]); } } }

December 7, 2011 at 3:01 PM

import java.util.*; public class Smallest { public static void main(String[] args) { Scanner kybd = new Scanner(System.in); int[] numbers = new int[10]; System.out.println("Enter 10 integers: "); for (int i = 0; i < numbers.length; i++) { numbers[i] = kybd.nextInt(); } int smallest = numbers[0]; int SmallestLocation = 0; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < smallest) { smallest = numbers[i]; SmallestLocation = i; } } System.out.println("Smallest value: " + smallest); System.out.println("Location of largest value: " + SmallestLocation); System.out.println("Numbers in reverse order: "); for (int i = numbers.length-1; i >=0; i--) { System.out.println(numbers[i]); } } }

Related Tutorials/Questions & Answers: