Computer Science, asked by sunitazirange, 7 months ago

Take 10 integer inputs from user and store them in an array. Again ask user to give a number. Now, tell user whether that number is present in array or not write a java program.

Answers

Answered by hoangmustang
12

Answer:

CHECK OUT MY SOLUTION>IF IT PRESENTS: TRUE, FALSE OTHERWISE.

import java.util.*;

public class isItPresent {

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int [] a = new int[10];

 boolean present = true;

 for(int i = 0; i < a.length; i++) {

  a[i] = input.nextInt();//take 10 inputs from the user

 }

System.out.println("Please enter the number you want to check: ");

int number = input.nextInt();

for(int j : a)  

if(j != number)

 present = false;

System.out.println(present);

}

}

Explanation:

MARK ME BRAINLIEST IF IT HELPS YOU!

Answered by kharodawalam
6

Answer:

I have just made modify in the given answer Above It will exactly print The true or false statment.

Explanation:

import java.util.Scanner;

public class Main {

       private static Scanner scanner = new Scanner(System.in);

       public static void main(String[] args) {

           int[] a = new int[5];             //install the array

           boolean present = false;                // putting flag condition

           for (int i = 0; i < a.length; i++) {            // taking values

               System.out.println("enter number \r");

               a[i] = scanner.nextInt();

           }

           System.out.println("enter number to check ");

           int number = scanner.nextInt();             // taking values of checking

           for (int j:a) {

               if (j == number)

                   present = true;

           }

           System.out.println(present);     // Output the value is True or False

       }

}

Similar questions