OOP-JAVA Practical 10

OOP-JAVA Practical 10
  • Aim: Write a test program that prompts the user to enter ten numbers, invoke a method to reverse the numbers, display the numbers.
  • Code:
    import java.util.Scanner;
    public class practical10{
        public static void reversearray(int num[]){
            for(int j=0;j<num.length/2;j++){
                int temp;
                temp=num[j];
                num[j]=num[num.length-j-1];
                num[num.length-j-1]=temp;
            }
        }
        public static void main(String[] args){
            int array[]=new int[10],i;
            Scanner s= new Scanner(System.in);
            System.out.println("Enter 10 numbers");
            for(i=0;i<10;i++){
                array[i]=s.nextInt();
            }
            reversearray(array);
            System.out.println("after reversing");
            for(i=0;i<10;i++){
                System.out.print(" "+array[i]);
            }
        }
    }
  • Output:
    Output of practical 10

Comments