Example of if else program
Answers
Explanation:
The if statement evaluates the test expression inside the parenthesis ().
If the test expression is evaluated to true, statements inside the body of if are executed.
If the test expression is evaluated to false, statements inside the body of if are not executed.
Answer:
import java.util.*;
class Prime_no
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements to be entered");
int n=sc.nextInt();
int a[]=new int[n];
int f;
System.out.println("Enter "+n+" elements");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("Prime numbers:");
for(int i=0;i<n;i++)
{
f=0;
for(int j=1;j<=a[i];j++)
{
if(a[i]%j==0)
f++;
}
if(f==2)
System.out.println(a[i]);
}
}
}