[JAVA Assignment] Write a program to allow user to enter 10 Integers and writes the smallest number
Hey Friends, main motive to write this post is to enhance your programming skills by practicing it. As this is one of my assignment question.It will very helpful you to enhace your programming skills.
In this question you will use Scanner methos to input data from uses, loops and conditional Statements.
Here is the Code-
import java.util.Scanner;
class User1
{
public static void main(String args[])
{
int arr[]=new int[10];
int smallest=32768, temp;
Scanner input=new Scanner(System.in);
System.out.println("enter 10 integers");
for(int i=0;i<10;i++)
{
arr[i]=input.nextInt();
}
for(int i=0;i<10;i++)
{
if(arr[i]<smallest)
{
temp=smallest;
smallest=arr[i];
arr[i]=temp;
}
}
System.out.print("smallest number="+smallest);
}
}
You can download source code with class file from here
In this question you will use Scanner methos to input data from uses, loops and conditional Statements.
Here is the Code-
import java.util.Scanner;
class User1
{
public static void main(String args[])
{
int arr[]=new int[10];
int smallest=32768, temp;
Scanner input=new Scanner(System.in);
System.out.println("enter 10 integers");
for(int i=0;i<10;i++)
{
arr[i]=input.nextInt();
}
for(int i=0;i<10;i++)
{
if(arr[i]<smallest)
{
temp=smallest;
smallest=arr[i];
arr[i]=temp;
}
}
System.out.print("smallest number="+smallest);
}
}
You can download source code with class file from here
Comments
Post a Comment