Answer: Following code is in java language :-
import java.lang.Math;
public class
{
public static void main(String args[])
{
printTwoDigit(6); //6 is the number of random numbers to be generated
}
public static void printTwoDigit(int n)
{
int i = 0;
int arr[]=new int[n]; //will declare a array of n size
int flag=0;
while(i<n)
{
arr[i] = 10 + (int)(Math.random()*10); //produce random number each time
System.out.println(arr[i]+" "); //print all random numbers
i++;
}
for(i=0;i<n;i++)
{
if(arr[i]==13) //to check if 13 was generated
{
flag=1;
break;
}
}
if(flag==1)
System.out.println("we saw a 13"); //this line is mentioned in question
else
System.out.println("no 13 was seen"); //this line is mentioned in question
}
}
OUTPUT :
15
11
15
19
13
19
we saw a 13
Step-by-step explanation:
- In the above code, an array is declared with size n(which is passed as an argument to the function) to store the list of all random number produced.
- Random() is multiplied by 10 so that it can produce a number 10 numbers starting from 0 and then 10 is added to the generated number so that minimum value generated would be 10.
- All numbers generated are printed to console n times and stored in arr.
- After that arr is checked for value 13 so it can print whether 13 was produced or not.