GTU OOP Program - 10

10). Write a test program that prompts the user to enter ten numbers, invoke a method to reverse the numbers, display the numbers.

import java.util.Scanner;

class Program_10 {

    public static void reverse(int list[]) {
        int temp;
        for (int i = 0, j = list.length - 1; i < list.length / 2; i++, j--) {
            temp = list[i];
            list[i] = list[j];
            list[j] = temp;
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int numbers[] = new int[10];

        // prompt the user to enter ten numbers
        System.out.print("Enter ten numbers : ");
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = input.nextInt();
        }

        // Call reverse nethod to reverse the numbers
        reverse(numbers);

        // display the numbers
        System.out.print("Numbers in Reverse order are : ");
        for (int j : numbers) {
            System.out.print(j + " ");
        }
        System.out.println();
    }
}

Output
cse gtu, gtu study material for computer engineering students gujarat technological university oop lab manual solution

gtu oop lab manual,

oop GTU Practical,

oop Programs,

Object oriented Programming,

Gtu study material 3140705,

OOP 3140705,

oop practical list,

Java Programming,

gtu oop practical,

oop lab solution gtu

Comments

YouTube

Popular posts from this blog

GTU OOP Program - 21

GTU OS Program - 3

GTU OOP Program - 1