0

Write a program to input 10 numbers and print the smallest number

please give the solution in java

17th Dec 2017, 2:53 PM
Myra
17 ответов
+ 29
1 more thing , u can do it for n numbers by using a for loop &an int array to get the user input & then apply ur method for sorting ☺ //@naveen , verify ur answer 1 again ... might array will get out of bound ☺
17th Dec 2017, 3:29 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 27
it would be better , if u show the code first //& we will help to correct it ☺
17th Dec 2017, 2:56 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 25
yes , it can be done using for loop //think more ☺ 👍 , use array also 👍👍👍 , now u can make it //@peerzada , let him also try☺
17th Dec 2017, 3:08 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 21
//👉 it can work for n numbers 😉👍 https://code.sololearn.com/c6OtUBc1HpTE/?ref=app
17th Dec 2017, 6:00 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 6
@ Gaurav Maybe he has some emergency haha... i thought he may need some code to look into. He may not be well acquainted with java collections. 😃
17th Dec 2017, 3:16 PM
Peerzada Burhan
Peerzada Burhan - avatar
+ 5
I have an idea! Make a function that finds the minimum number between two numbers and then do this: min(min(min(min(.........., num1), num2)......num10);
17th Dec 2017, 2:59 PM
Naveen Maurya
Naveen Maurya - avatar
+ 5
Here you go: import java.util.*; public class Program { public static void main(String[] args) { ArrayList<Integer> numbers= new ArrayList<>(); Scanner in = new Scanner(System.in); for(int i=0;i<=9;i++){ numbers.add(in.nextInt()); } System.out.println(Collections.min(numbers)); } }
17th Dec 2017, 3:07 PM
Peerzada Burhan
Peerzada Burhan - avatar
+ 4
thanks to everyone @peerzada @Naveen Maurya @Gaurav Agarwal
17th Dec 2017, 3:25 PM
Myra
+ 4
@Manya You're WELCOME!
17th Dec 2017, 3:26 PM
Naveen Maurya
Naveen Maurya - avatar
+ 3
I don't know how to begin
17th Dec 2017, 2:57 PM
Myra
+ 3
it is required by for loop
17th Dec 2017, 3:00 PM
Myra
+ 3
its saying split multiple input in separate lines.... wht to do ? @Gaurav Agarwal
17th Dec 2017, 6:02 PM
Myra
+ 3
ok thanks
17th Dec 2017, 6:08 PM
Myra
+ 2
//Declare an array which holds the 10 numbers! //Declare a number variable i! //And then....... for (i=0; i<10; i++) { numberArray[i+1] = min(numberArray[i], numberArray[i+1]); } //The minimum is numberArray[9]
17th Dec 2017, 3:25 PM
Naveen Maurya
Naveen Maurya - avatar
+ 2
@Gaurav Agarwal I'll try
17th Dec 2017, 5:31 PM
Myra
+ 2
@Gaurav Agarwal https://code.sololearn.com/c7NdA2VJw6mQ/?ref=app I guess it can be done this way. Do notify if you find some loopholes 🙂
17th Dec 2017, 5:41 PM
Myra
0
For loop
16th May 2023, 8:05 AM
Raj Jaiswal
Raj Jaiswal - avatar