Use a while loop to write a program that given a vector of n

Use a while loop to write a program that given a vector of numbers computes how many numbers are greater than 10. Use Array2 to check your program.

Array2 = 7, 5, 10, 3, 11, 4, 1, 12, 15, 2

Solution

//in any programming language the while condition look like the following code

package com.mt.classes;

public class Demo {
   public static void main(String[] args) {
      
       int[] array2={7,5,10,3,11,4,1,12,15,2};
       int count=0;
       int i=0;
       while(i<array2.length)
       {
           if(array2[i]>10)
           {
               count++;
           }
           i++;
       }
       System.out.println(\"the no of elements greater than 10 are\ \"+ count);
   }

}

output

the no of elements greater than 10 are
3

Use a while loop to write a program that given a vector of numbers computes how many numbers are greater than 10. Use Array2 to check your program. Array2 = 7,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site