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: |

As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. best-secure-messaging-apps-shutterstock-1892950018.jpg Hashtags Informative
from us


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