write a program for Given an array of type int, print true if
every element is 1 or 4.
only14([1, 4, 1, 4]) true
only14([1, 4, 2, 4]) - false
only14(01. 11) - true
Answers
import java. util. *
class True_false
{
public static void main ( String args [] )
{
Scanner sc = new Scanner ( System.in ) ;
int i, k=0 ;
int a [] = new int [ ] ;
System.out.println (" Enter the array elements ");
for ( i=0;i<a.length;i++)
{
a [i] = sc.nextint();
}
System.out.println ("The array elements are");
for ( i=0;i<a.length;i++)
{
System.out.println ( a[ i ] + " " ) ;
}
// checking the elements
for ( i=0;i<a.length;i++)
{
if ( a [ i ] == 1 || a [ i ] == 4 )
k++;
}
if ( k == a.length )
System.out.println (" True ");
else
System.out.println (" False ");
}
}
Hope it HELPS
plzzzz mark as BRAINLIEST
Answer:
import java.util.*;
public class arrat_type_int {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
int size=scanner.nextInt();
int arr[]=new int[size];
int count=0;
for(int i=0;i<arr.length;i++)
{
arr[i]=scanner.nextInt();
}
for(int i=0;i<arr.length;i++)
{
if(arr[i]==1 || arr[i]==4)
{
count=1;
break;
}
}
if(count==1)
{
System.out.println("true");
}
else
{
System.out.println("false");
}
}
}
Explanation: