How to write a program for Method ,print simple array in core java.?

Program for Method demo in core java :

Hello Friends, 

Today I will give you an example for writing a program for display how to use method in core java.

Code:

public class Methoddemo {
public static void main (String[] args)
{
int a=80;
int b=290;
int c=Sum(a,b);
System.out.println(“The sum of “+a+” and “+b+”  is =”+c);
}
public static int Sum(int num1,int num2)
{
int ans;
ans=num1+num2;
return ans;
}

}

Output :

The sum of 80 and 290  is =370

Program for print simple array in core java :

Hello Friends, 

Today I will give you an example for writing a program for print simple array in core java.

Code:

public class sample2darray {

public static void main(String args[])

{

int a[][]=new int [3][3];

int k=1;

System.out.print(“nStoring the numbers in array”);

for(int i=0;i<3 div="" i="">

{
for(int j=0;j<3 div="" j="">

{
a[i][j]=k+1;
k=k+1;
}
}
System.out.println(“nYou have stored…”);
for(int i=0;i<3 div="" i="">

{
for(int j=0;j<3 div="" j="">

{
System.out.print(” “+a[i][j]);
}
System.out.println();
}
}
}

Output :

Storing the numbers in array
You have stored…
 2 3 4
 5 6 7
 8 9 10

Leave a Reply

Your email address will not be published. Required fields are marked *