Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- Random rand = new Random();
- Scanner scan = new Scanner(System.in);
- int[] num = new int[10];
- int total = 0;
- boolean found = false;
- int top = num[0];
- System.out.print("Array 1: ");
- for( int x = 0; x < num.length; x++){
- num[x] = rand.nextInt(100)+1;
- System.out.print( num[x] + " ");
- }
- System.out.print("\nValue to find: ");
- int value = scan.nextInt();
- for (int x: num){
- if( x == value){
- total = total + 1;
- found = true;
- }
- }
- if(found){
- System.out.println(value + " is in the array.");
- }
- if(!found){
- System.out.println(value + " is not in the array.");
- }
- System.out.println(value + " was found a total of: " + total + " time(s)." );
- for (int i : num) {
- if (i > top) {
- top = i;
- }
- }
- System.out.println("The largest number is: " + top);
- for(int x = 0; x < num.length; x++){
- if(num[x] == top){
- System.out.println("It is in slot: " + x);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement