0% found this document useful (0 votes)
9 views

OOP_Lab_Manual_1

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)
9 views

OOP_Lab_Manual_1

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/ 4

Department of

Computer Science and Engineering

Title: C - Java Syntax Similarity : Array,


Conditionals, Loops

Object Oriented Programming


CSE 202

Green University of Bangladesh


1 Objective(s)
• To gather knowledge of java syntax, array conditions and loops.
• To implement different types of problem like prime number, Fibonacci number, odd even number checking
solved in Java.

2 Problem analysis
In structured programming we learn different types of problem like prime number generation, Fibonacci num-
ber generation, checking odd and even numbers. In this lab, we will solve all types of this problem in java
programming language, .

3 Prime Number Generation Code Implementation in Java


1 /* Prime number generation code in java */
2 import java.util.Scanner;
3 public class Rayhan
4 {
5 public static void main(String args[])
6 {
7 int num, i, count=0;
8 Scanner scan = new Scanner(System.in);
9 System.out.print("Enter a Number = ");
10 num = scan.nextInt();
11 for(i=2; i<num; i++)
12 {
13 if(num%i == 0)
14 {
15 count++;
16 break;
17 }
18 }
19 if(count == 0)
20 {
21 System.out.println("This is a Prime Number");
22 }
23 else
24 {
25 System.out.println("This is not a Prime Number");
26 }
27 }
28 }

4 Input/Output
Output of the program is given below.

Enter a number: 5
This is a Prime Number
Enter a number: 10
This is not a Prime Number

© Dept. of Computer Science and Engineering, GUB


5 Fibonacci Number Generation Code Implementation in Java
1 /* Fibonacci number generation code in java */
2 import java.util.Scanner;
3 public class Rayhan
4 Page | 3
5 {
6 public static void main(String[] args)
7 {
8 int n, a = 0, b = 0, c = 1;
9 Scanner s = new Scanner(System.in);
10 System.out.print("Enter value of n = ");
11 n = s.nextInt();
12 System.out.print("Fibonacci Series = ");
13 for(int i = 1; i <= n; i++)
14 {
15 a = b;
16 b = c;
17 c = a + b;
18 System.out.print(a+" ");
19 }
20 }
21 }

6 Input/Output
Output of the program is given below.

Enter value of n: 5
Fibonacci Series= 0 1 1 2 3
Enter value of n: 9
Fibonacci Series= 0 1 1 2 3 5 8 13 21

7 Discussion & Conclusion


From this experiments we learn about how to write a program in java. The different types of problem which
we were practicing in structured programming, we just try to solve this using java language.

8 Lab Task (Please implement yourself and show the output to the
instructor)
1. Implement summation of factorial number in java.

8.1 Problem analysis


Enter a number from user. After taking the number find the factorial of the particular number. According to
the summation equation, we have to find out the summuation of factorial numbers and should be printed on
screen. However, Input must be taken from users.

9 Lab Exercise (Submit as a report)


• Implement checking of odd and even number

© Dept. of Computer Science and Engineering, GUB


Figure 1: Problem equation

• Implement summation of factorial odd number series.

10 Policy
Copying from internet, classmate, seniors, or from any other source is strongly prohibited. 100% marks will be
deducted if any such copying is detected.

© Dept. of Computer Science and Engineering, GUB

You might also like