Monday, June 22, 2015

Dietel - Java How to Program 9th Edition ( include Examples)

Java How To Program, 10th Edition (Early Objects)Paul Deitel , Harvey Deitel

Java The Complete Reference 8th 2012

Java The Complete Reference 9th Edition

Introduction to Algorithms-3rd edi-Cormen

Data Structures : A Pseudocode Approach with C

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 _ toString

 

 

package ArrayMethod;

import java.util.Arrays;

public class toString {

public static void main(String[] args) {
int a[] = { 3, 4, 2, 1 };
System.out.println(a);
System.out.println(Arrays.toString(a));
}

}

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 fill function

package ArrayMethod;

import java.util.Arrays;

public class fill {

public static void main(String[] args) {
int[] a = { 3, 4, 2, 1 };
System.out.println(Arrays.toString(a));
Arrays.fill(a, 9);
System.out.println(Arrays.toString(a));
}

}

Java–Array equals function

Java–Array equals function

 

 

package ArrayMethod;

import java.util.Arrays;

public class equals {

public static void main(String[] args) {
int a[] = { 3, 4, 2, 1 };
int b[] = { 3, 4, 2, 1 };
int c[] = { 3, 4, 2 };
System.out.println(Arrays.equals(a,b));
System.out.println(Arrays.equals(a,c));

}

}

Java-Array copy

Java-Array copy

 

 

package ArrayMethod;

public class Copy {


public static void main(String[] args) {
int[] a = { 1, 2, 3};
int[] copy = a;

for(int i=0;i<copy.length;i++)
{
System.out.println(copy[i]);
}

}

}

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

using Scanner

 

package Normal;
import java.util.Scanner;

public class InputOutput {
public static void main(String[] args) {
System.out.println("Please Input : ");

Scanner objScanner=new Scanner(System.in);

int a =objScanner.nextInt();

System.out.println(a);
}

}