An array is called vanilla if all its elements are made up of the same digit. For example {1, 1,
11, 1111, 1111111} is a vanilla array because all its elements use only the digit 1.
However, the array {11, 101, 1111, 11111} is not a vanilla array because its elements
use the digits 0 and 1.
Write a program that reads a string from a user that represent array and check if its a vanilla
array. Otherwise it will print message as in the sample run shown below and should continue to
allow the user to enter values. The program will terminate only if the user press the "Enter" key
without entering any value. For example the '{1}' is a vanilla array since all elements use the
same digit. Where '{11, 22, 13, 34, 125}' array is not vanilla array becuase elements used 5
different digits.

See Answers (1)

Accepted Answer

Using the knowledge in computational language in JAVA it is possible to write the code that An array is called vanilla if all its elements are made up of the same digit. Writting the code:import java.util.Scanner;  public class Main{ public static void main(String[] args) {                 int n;  Scanner sc=new Scanner(System.in);  System.out.print("Enter the number of elements you want to store: ");  //reading the number of elements from the that we want to enter  n=sc.nextInt();  //creates an array in the memory of length 10  int[] array = new int[10];  System.out.println("Enter the elements of the array: ");  for(int i=0; i<n; i++)  {  //reading array elements from the user   array[i]=sc.nextInt();  } System.out.println("Array elements is: ");  for(int i=0; i<n; i++)  {      System.out.print(array[i]+" ");   } System.out.println("\n");  int res=0;  int t;int k; for(int i=0; i<n; i++)  {     t=array[i];   while(t>0)   {       k=t%10;       t=t/10;       if(k==0)       {           res=1;           break;       }   }if(res==1)   {System.out.println("False it is not vanilla array");         break;   }  }if(res==0){    System.out.println("True it is  vanilla array");  }See more about JAVA at brainly.com/question/12975450#SPJ1

Related Question in Computers and Technology