0% found this document useful (0 votes)
15 views8 pages

Oopl Exp 1

Uploaded by

mdahmerusmani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Oopl Exp 1

Uploaded by

mdahmerusmani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Bharati Vidyapeeth (Deemed to be University)

Department of Engineering and Technology


Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

EXPERIMENT 1

Name: Abdul Moiz Usmani Roll No: 33

Subject: Object Oriented Program Class/Batch: FY-AIML/B2

Date of Performance: Date of Submission:

AIM

AIM:- TO IMPLEMENT PROGRAMS IN JAVA FOR INPUT HANDLING

Theory/Procedure/Algorithm
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

IMPLEMENTATION

1. Write a program in java to display name, address ,college name, roll no ,without any
variable

INPUT:-

class Detail //creating class


{
public static void main (String args[]) //main program starts
{
System.out.println("Name - Abdul Moiz");
System.out.println("Address - Mumbai 70");
System.out.println("College - BVDU");
System.out.println("Roll NO. - 33");
} //end of main
} //end of class

OUTPUT:-
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

2) Write a program to accept the following data types Integer,Double,Float,Character,Byte


a) Scanner class
INPUT:-
import java.util.*;
class DataType //creating class
{
public static void main (String args[]) //main program
{
int i; //accepting variables
char c;
float f;
double d;
byte b;
Scanner in = new Scanner(System.in); //creating object for class
System.out.println("Enter an integer = ");
i= in.nextInt(); //taking input for int
System.out.println("Enter an character = ");
c= in.next().charAt(0); //taking input for char
System.out.println("Enter an Float = ");
f= in.nextFloat(); //taking input for float
System.out.println("Enter an double = ");
d= in.nextDouble(); //taking input for double
System.out.println("Enter an byte = ");
b= in.nextByte(); //taking input for byte
System.out.println("Integer = " +i+ "\nCharacter = " +c+ "\nFloat = " +f+ "\nDouble = "
+d+ "\nByte = " +b);
}
} //end of class
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

OUTPUT:-

B) DataInputStream:-
INPUT:-
import java.io.*;
class Dis
{
public static void main (String arg[]) throws IOException
{
int a; //accepting variables
String s;
float f;
double d;
DataInputStream m = new DataInputStream(System.in); //creating object for class
System.out.println("Enter a String");
s=m.readLine(); //input reading in DIS
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

System.out.println("Enter an Integer");
a=Integer.parseInt(m.readLine());
System.out.println("Enter a Float");
f=Float.parseFloat(m.readLine()); //values of float into string
System.out.println("Enter a double");
d=Double.parseDouble(m.readLine());
System.out.println("Double = " +d+ "\nInteger = " +a+ "\nFloat = " +f+ "\nString = " +s);
}
}

OUTPUT:-
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

3. Write a program in java to accept a number from the user and display whether its even
or odd.
INPUT:-
import java.util.*; //using scanner class
class EvenOdd
{
public static void main (String args[]) //start
{
int a;
Scanner eo =new Scanner (System.in); //object for class
System.out.println("Enter a Number = ");
a = eo.nextInt(); //taking input as scanner class
if (a%2==0) //using if else loop
{
System.out.println(a+ " is EVEN !!");
}
else
{
System.out.println(a+ " is ODD !!!");
}
}
}

OUTPUT:-
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

4. Addition Using Commond Line Arguments


INPUT:-
import java.io.IOException;
class Add //creating class
{
public static void main (String arg[]) throws IOException
{ //start
int a;
int b;
int c;
a=Integer.parseInt(arg[0]); //using command line argument
b=Integer.parseInt(arg[1]);
c=a+b;
System.out.println("The Addition of " +a+" and "+b+" is "+c);
}
}

OUTPUT:-
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning

Conclusion

CONCLUSION:- WE HAVE SUCCESFULLY IMPLEMENTED INPUT HANDLING


PROGRAMS IN JAVA

Assessment

Timely Submission Presentation Understanding Total


Sign
(7) (06) (12) (25)

You might also like