Showing posts with label java Discussion. Show all posts
Showing posts with label java Discussion. Show all posts

Friday, May 13, 2016

example for getset array

Here i am going to show you the use of get set array in java.


package setgetarray;
import java.util.Scanner;
public class SetGetArray {

    int i;

    Scanner sc= new Scanner(toString());
    int rollNo[]=new int[2];
    float marks[] = new float[2];
    String info[]=new String[2];

    public void setInfo(){

        System.out.println("Enter the student no:");
        //this.n= sc.nextInt();
        for (i=0;i<2;i++){
            System.out.println("student roll:");
            sc.nextInt();
            System.out.println("student marks");
            sc.nextFloat();
            System.out.println("student info");
            sc.nextLine();
        }

    }
    public void getInfo(){
        System.out.println("student info:");
        for(i=0;i<2;i++){

            System.out.println("student roll:"+rollNo);
            System.out.println("student marks"+marks);
            System.out.println("student info"+info);
        }

    }
}

Tuesday, May 10, 2016

java functions

java Functions are most strong to handle the operations with global variables and arguments passed to it. the variables defined inside the java functions are always local and  are only available inside function only. Function can return any value of the class type. We can consider data type int, float, String etc as a Class type. In function one can return Object typed java.
Here is one simple function illustrated for concept of java array.
 public void setStudentArray(){
        for(int i=0;i<num;i++){

            HasStudent student=new HasStudent();
            System.out.println("======***********========");
            student.name=setName();
            student.Address=setAddress();
            student.rollNo=setRoll();
            stdArray[i]=student;
            System.out.println("======***********========");

        }
    }
In this function there is no return type and no argument. only local and global variables available inside the functions are processed with this function and are available when callng the function

we can declare function with the return type as follows:

(Access_Specifier) (ClassName) functionName(arguments.
class definintions;
processing of local and global datas.
return(Object of class);
}