import java.io.*;

public class getLowestValue {
	public static void main(String[]args) throws Exception {
		
		DataInputStream input=new DataInputStream(System.in);
		
		System.out.println("Get lowest value ");
		int a[]=new int[10];
		int x =0, i=0, j=0, tmp=0;
		
		// display and get inputs [5]
		for (x=0;x<5;x++){
			System.out.print(x+" Enter a number: ");
			a[x] = Integer.parseInt(input.readLine());
			
		}
		
		// sorting
		for (x=0;x<5;x++){ // loop for 5 times
			i = x; // store value of x to i
			for (j=x+1;j<5;j++){ 
				if (a[j] < a[i]) 
					i =j; 
			}
			
			tmp = a[x]; 
			a[x]=a[i]; 
			a[i]=tmp; 
		}
					x=0;
					System.out.println(a[x]+ " is the lowest!");

					
	}
}

THIS IS THE PROBLEM:
write a program using one-dimensional array that determines the lowest value among the five input values typed from the keyboard and print the difference of each, value from the lowest.
Like if the user inputs: 56421
It will display:
4
5
3
1

My problem is: I was able to get the lowest number on all the user inputs but the thing is, i scrambled the array in the processed. I arranged it into lowest to highest. My question would be how would i be able to get the lowest value on the inputs without disarranging the original sequence of inputs?

Try to use the methods available in java to show some smart work.
It willhelp toreduce thecomplexity.

Dont try to arrange the array.Keep it intact.
Try to find the lowest number then get the diffeerences
between them without rearranging the array.

Try to use the methods available in java to show some smart work.
It willhelp toreduce thecomplexity.

Dont try to arrange the array.Keep it intact.
Try to find the lowest number then get the diffeerences
between them without rearranging the array.

Thanks for suggestion. But I just don't know another method on how I can check for the next number without disarranging the array. If you have suggestions how, I would appreciate it. Thanks though

Instead of sorting the array just to find the minimum, loop though the array continuously updating the 'min' variable. Something like:

int min = myArray[0];
for(int i = 1, limit = myArray.length; i < limit; ++i)
{
    if(myArray[i] < min)
        min = myArray[i];
}
System.out.println("The minimum is " + min);

To add to the previous suggestion by ~s.o.s~ of updating min variable -Initialize min variable with zero and do this min checking in the same loop where user provides inputs; Then have another loop to print the differences. This way you will acheive it in two loops instead of three.

> Initialize min variable with zero and do this min checking in the same loop where user provides inputs;
What happens when all the inputs are greater than 0? You end up getting zero as the minimum which is the wrong answer.

To get around that, you would have to use a modified version of the loop as:

int min = 0;
for(int i = 0; i < 5; ++i)
{
    // accept input in 'num'
    if(i == 0)
         min =   num;
    else if(num < min)
        min = num;    
}

Thanks everyone! I was able to make it work..thanks for the help!:)

kindly please help to solve my problem???
create a program that the user allow to input a 5 integers, that looking the lowest value?

kindly please help to solve my problem???
create a program that the user allow to input a 5 integers, that looking the lowest value?

Create your own thread and show effort. No one is going to do your work for you.

kindly please help to solve my problem???
create a program that the user allow to input a 5 integers, that looking the lowest value?

It would be useful to read a Thread before posting to it. Perhaps your question has already been answered.

commented: Good point. +9

hey can any one help me??

i have 2 develop a code to find the lowest and unique number from a array..i thot of sorting them and then comparing the lowest number with othe numbers but i m feelin it wont work...pls help me out...

Read a thread before posting to it. Your question has already been answered

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.