Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner input = new Scanner(System.in);
- System.out.print("Enter the size of the array: ");
- int numbers = input.nextInt();
- // Declare an array called numbers with a size of 10
- int[] numbers1 = new int[numbers];
- insertRandomNumbers(numbers1);
- // Print size of numbers
- System.out.println("Initial Array: ");
- for (int i = 0; i < numbers1.length; i++) {
- System.out.print(numbers1[i] + " ");
- }
- System.out.println("");
- //Print First and Last Elements
- System.out.println();
- System.out.println("First and Last Elements");
- int [] lastStep = lastStep(numbers1);
- for (int i = 0; i < lastStep.length; i++) {
- System.out.print(lastStep[i] + ", ");
- }
- } // end main
- public static int[] lastStep(int[] numbers1) {
- //to get first
- int [] firstElement= numbers1.get(0);
- //last number
- int [] lastElement= numbers1.get(numbers1.size()-1);
- }
- return lastStep;
- public static void insertRandomNumbers(int[] x) {
- for (int i = 0; i < x.length; i++) {
- x[i] = random();
- // System.out.print(x[i] + " ");
- }
- // System.out.println();
- }
- public static int random() {
- int r = 0 + (int) (Math.random() * (101 - 0)) + 0;
- return r;
- }
- //to get first
- int [] firstElement= numbers1.array[0];
- //last number
- int [] lastElement= numbers1.array[numbers1.size()-1];
- }
- return lastStep;
- public static string firstAndLast(int[] numberArray)
- {
- return numberArray[0] + ", " + numberArray[numberArray.length - 1];
- }
- System.out.println(firstAndLast(numbers1));
- var i = int[] //Array of random numbers
- var x = int[y]
- /*Then get `x` instead of retrieving the numbers from the whole array.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement