Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Example program of geting data from user using Wrapper Class

In below program, we will convert instance variable into wrapper class!

If you want to get data from user, you must have to import the java class from library, you can do this by import weather "java.io", "java.util" or "java.scanner", you can use any one of this ! 


import java.io.*;

public class employee{

int empnumber;
String name;
String add;

private void getdata()throws IOException{

DataInputStream d = new DataInputStream(System.in);

System.out.println("Enter Employee Number: ");
empnumber= Integer.parseInt(d.readLine()); 

//here we convert integer into wrapper class


System.out.println("Enter Emplyee Name: ");
name = d.readLine(); 

//in both string value,we haven't convert because String is a class not variable so no need to convert in to wrapper class

System.out.println("Enter Employee Address: ");
add=d.readLine();
}

private void display()throws IOException {

System.out.println(empnumber+"\t"+name+"\t"+add);

}



public static void main(String args[])throws IOException{

employee e1 = new employee();
employee e2 = new employee();

e1.getdata();
e2.getdata();

e1.display();
e2.display();
}
}



This post first appeared on LET's START CORE JAVA !, please read the originial post: here

Share the post

Example program of geting data from user using Wrapper Class

×

Subscribe to Let's Start Core Java !

Get updates delivered right to your inbox!

Thank you for your subscription

×