Problem 2: Arrays

Based from the previous problem about arrays, here's another thing which is similar to that problem: Create a program that will allow the user to enter ten numbers and sort the numbers in an ascending and descending order. Then, display the highest and the lowest value of the ten numbers given by the user.

import java.io.*;
import java.util.Arrays;

public class Oc13
{
public static void main (String args[]) throws IOException
{

DataInputStream whatever = new DataInputStream (System.in);

int earth[] = new int [10];
int temp;

System.out.println("Enter 10 numbers: ");

for (int i = 0; i< earth.length/2; ++i ) { temp = earth[i]; earth[i] = earth[earth.length - i - 1]; earth[earth.length - i - 1] = temp; } System.out.println("Descending Order: " + Arrays.toString(earth)); System.out.println("Highest is " + earth[0]); // System.out.println("Lowest is " + earth[10]); } }

No comments:

Post a Comment

Extended Search

Custom Search
Hello World