JAVA_CODINGS Telegram 71
51. Example to Pass Arrays to function.

import java.util.*;
class PassingArraystoFunction
{
public static void main(String[] args)
{
int[] a;
int size;

Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

a = new int[size];

System.out.println("Enter elements in the array");
for(int i = 0 ;i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("The Elements of the array are : ");
for(int i = 0 ;i < size; i++)
{
System.out.print(a[i] + " ");
}

//Passing array to the function
addElements(a, size);
}

public static void addElements(int[] a , int size)
{
int sum = 0;

for(int i = 0; i < size; i++)
{
sum += a[i];
}

System.out.println("\nSum of the elements of arrays is : "+sum);
}
}

@java_codings



tgoop.com/java_codings/71
Create:
Last Update:

51. Example to Pass Arrays to function.

import java.util.*;
class PassingArraystoFunction
{
public static void main(String[] args)
{
int[] a;
int size;

Scanner sc = new Scanner(System.in);

System.out.println("Enter size of array");
size = sc.nextInt();

a = new int[size];

System.out.println("Enter elements in the array");
for(int i = 0 ;i < size; i++)
{
a[i] = sc.nextInt();
}

System.out.println("The Elements of the array are : ");
for(int i = 0 ;i < size; i++)
{
System.out.print(a[i] + " ");
}

//Passing array to the function
addElements(a, size);
}

public static void addElements(int[] a , int size)
{
int sum = 0;

for(int i = 0; i < size; i++)
{
sum += a[i];
}

System.out.println("\nSum of the elements of arrays is : "+sum);
}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Share with your friend now:
tgoop.com/java_codings/71

View MORE
Open in Telegram


Telegram News

Date: |

How to create a business channel on Telegram? (Tutorial) Concise Ng Man-ho, a 27-year-old computer technician, was convicted last month of seven counts of incitement charges after he made use of the 100,000-member Chinese-language channel that he runs and manages to post "seditious messages," which had been shut down since August 2020. Telegram is a leading cloud-based instant messages platform. It became popular in recent years for its privacy, speed, voice and video quality, and other unmatched features over its main competitor Whatsapp. With the administration mulling over limiting access to doxxing groups, a prominent Telegram doxxing group apparently went on a "revenge spree."
from us


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM American