0
Write a program to input 10 numbers and print the smallest number
please give the solution in java
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 ☺
+ 27
it would be better , if u show the code first
//& we will help to correct it ☺
+ 25
yes , it can be done using for loop
//think more ☺ 👍 , use array also 👍👍👍 , now u can make it
//@peerzada , let him also try☺
+ 21
//👉 it can work for n numbers 😉👍
https://code.sololearn.com/c6OtUBc1HpTE/?ref=app
+ 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. 😃
+ 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);
+ 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));
}
}
+ 4
thanks to everyone @peerzada @Naveen Maurya @Gaurav Agarwal
+ 4
@Manya You're WELCOME!
+ 3
I don't know how to begin
+ 3
it is required by for loop
+ 3
its saying split multiple input in separate lines.... wht to do ? @Gaurav Agarwal
+ 3
ok thanks
+ 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]
+ 2
@Gaurav Agarwal I'll try
+ 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 🙂
0
For loop