Write a class PassArray to accept an array size and get the array values and use function to display the next number of all array values.

0

  Assignment: Module 03- Part 02

Write a class PassArray to accept an array size and get the array values and use function to display the next number of all array values.

Write a class PassArray to accept an array size and get the array values and use function to display the next number of all array values.

Input: 

Enter the number of elements 3

Enter the number 12

Enter the number 3

Enter the number 5

Output:

Array elements from method..

a[0]=13

a[1]=4

a[2]=6

class PassArray {
   public static void main(String[] args) {
      int size;
      int[] array;
      Scanner scan = new Scanner(System.in);
      
      System.out.print("Enter the number of elements: ");
      size = scan.nextInt();
      array = new int[size];
      
      System.out.println("Enter the array elements: ");
      for (int i = 0; i < size; i++) {
         array[i] = scan.nextInt();
      }
      
      System.out.println("Array elements from method..");
      display(array);
   }
   
   public static void display(int[] array) {
      for (int i = 0; i < array.length; i++) {
         System.out.println("a[" + i + "] = " + (array[i] + 1));
      }
   }
}   

The output would be:

Enter the number of elements: 3
Enter the array elements: 
12
3
5
Array elements from method..
a[0] = 13
a[1] = 4
a[2] = 6   

👉Write a class OddExample to accept a number to find whether the number is Odd or Even👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates