Monday, June 22, 2015
Java Swap Parameter
Java Swap Parameter
package ArrayMethod;
import java.util.Arrays;
public class swapParameter {
public static void main(String[] args) {
int a[]={10,20,30};
System.out.println(Arrays.toString(a));
swapParameter(a,1,0);
System.out.println(Arrays.toString(a));
}
private static void swapParameter(int[] a, int i, int j) {
int temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
Java _ toString
Java–Array sort function
Java–Array sort function
package ArrayMethod;
import java.util.Arrays;
public class Sort {
public static void main(String[] args) {
int[] a = { 3, 2, 4, 1 };
Arrays.sort(a);
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
System.out.println(Arrays.toString(a));
Arrays.sort(a);
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
Java–Array fill function
Java–Array equals function
Java-Array copy
Java-fixed given
Java-fixed given
package Array;
import java.util.Scanner;
public class Size_fixed {
public static void main(String[] args) {
Scanner S =new Scanner(System.in);
System.out.println("Enter size of integer number :");
int n=S.nextInt();
int a[]=new int[n];
for(int i=0;i<a.length;i++)
{
a[i]=S.nextInt();
}
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
Java - Fixed_size
package Array;
import java.util.Scanner;
public class Fixed_size {
public static void main(String[] args) {
int a[]=new int[5];
Scanner S =new Scanner(System.in);
System.out.println("Enter 5 integer number :");
for(int i=0;i<a.length;i++)
{
a[i]=S.nextInt();
}
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
Java-Array Return
Java-Array Return
package Array;
import java.util.Random;
import java.util.Scanner;
public class ArrayReturn {
public static final Random random =new Random();
public static int [] getarray(int a)
{
int n[]=new int [a];
// Scanner scanner=new Scanner(System.in);
// for(int i=0;i<n.length;i++)
// {
// n[i]=scanner.nextInt();
// }
for(int i=0;i<n.length;i++)
{
n[i]=random.nextInt(100);
}
return n;
}
public static void main(String[] args) {
int n;
System.out.println("Enter size of array");
Scanner scanner=new Scanner(System.in);
n=scanner.nextInt();
int b[]=getarray(n);
for(int i=0;i<b.length;i++)
{
System.out.println(b[i]);
}
}
}
Java-Array different way
Java-Array different way
import java.util.Scanner;
public class ARRAYmain {
public static void main(String[] args) {
//first way
// int a[]=new int[100];
// a[0]=10;
// a[1]=11;
// a[2]=12;
// System.out.println(a[0]+" "+a[1]+" "+a[1]+" "+a[2]);
//second way
// int b[]={10,20,30};
//
// System.out.println(b[0]+" "+b[1]+" "+b[1]+" ");
//third way
// Scanner v = new Scanner(System.in);
// int cc=10;
// int c[]=new int [cc];
//forth way
int d[]={10,20,30};
for(int i=0;i<d.length;i++)
{
System.out.println(d[i]);
}
}
}
Saturday, June 20, 2015
Java–Input
Subscribe to:
Posts (Atom)