Вы находитесь на странице: 1из 3

JAVA BASIC SYNTAX

Declaring variable
Data types meaningful variable name;
E.g 1.: int numberOne;
double numberTwo;
float valueOne;
Variable initialising
Followed by example 1
numberOne=1;
numberTwo=2.3;
or
int numberOne=2;
Array Declaring
int arrayOne[] ;
or
int [] arrayOne;
Passing size to an Array
int arrayOne=new int[5];
passing value to an array
int arrayOne[]={1,2,3,4};
look: Size of this array is 5, values store in this array will be
from index(address) 0 to 4
Same for declaring all kind of variable like float, string, double
etc.

Tip : first letter in variable declaring should be in small


letter.

Helper class in array


Java has many inbuilt class like header file available in c or cpp
1) sort()----- it used to sort the value in a array in
ascending order
How to use in this program????
import java.util.Arrays
util
and printf() in c

this call the java array inbuilt class from


package, just like #include<stdio.h> for scanf();
//

int arrayOne[] ={4,3,2,1};


Arrays.sort(arrayOne);

Output:
1,2,3,4 // if u return arrayOne

2) length---used to find the length of an array


int arrayOne[] ={4,3,2,1};
int arrayLength;
arrayLength=arrayOne.length ;
//if you print this arrayLength your anser will be 4

3) arraycopy()-----used for copy the value from one


array to another array
How to use this in program???????????

int arrayOne[] ={4,3,2,1};


int arrayTwo[];
System.arraycopy(arrayOne,0 ,arrayTwo,0,arrayOne.length)
//if u print arrayTwo ur answer ll be 4 3 2 1
Explanation
System.arraycopy(source array name, index of source array,
destination array, index of destination, length of source
array);

STRINGS JAVA STRING DOCUMENT IS ATTACHED IN NEXT


ATTACHEMENT
IF U HAVE ANY PROBLEM IN READING THIS KINDLY
INTIMATE ME..... WILL GET BACK U SOON WITH SOME
BASIC SYNTAX.....

Вам также может понравиться