mercredi 7 novembre 2018

How to add the nth place of an output in a lambda sequence

So I needed to create program that gave me n amnt of random numbers out of a given range. Lets say it gives me 4 and 3 out the range

so the code result looks like this: 4 is the random number 3 is the random number

But i want to say 4 is the 'first' random number 3 is the 'second' random number

Scanner input = new Scanner(System.in);
                System.out.print("Enter lower limit of the range:");
                String lowerLimit = input.nextLine();
                int min = Integer.parseInt(lowerLimit);

                Scanner input1 = new Scanner(System.in);
                System.out.print("Enter higher limit of the range:");
                String higherLimit = input.nextLine();
                int max = Integer.parseInt(higherLimit);

                /*
                 * 
                 */
                Scanner input3 = new Scanner(System.in);
                System.out.print("How many numbers shall I print:");
                String amountPrinted = input3.nextLine();
                int amount = Integer.parseInt(amountPrinted);

                int amount1 = amount;
                int min1 = min;
                int max1 = max;
                Random random = new Random();
                random.ints(amount1, min1, max1).sorted().forEach(i -> System.out.println("Random number is " + i));
                
                
        }
        
}



Aucun commentaire:

Enregistrer un commentaire