Oopl Exp 1
Oopl Exp 1
EXPERIMENT 1
AIM
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:-
OUTPUT:-
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
OUTPUT:-
Bharati Vidyapeeth (Deemed to be University)
Department of Engineering and Technology
Kharghar, Navi Mumbai
Department of Artificial Intelligence and Machine Learning
Conclusion
Assessment