Introduction to JAVA Programing
[BCSL 506]
LAB REPORT FILE
Submitted To: Submitted By:
Prof. Neha Bhardwaj Poorva Yadav
Prof. Santosh Sharma Enroll. 0901CS151010
3rd Year 5th semester
1
1. Program to print sum of two numbers.
/**
Program to perform additon
*/
import java.util.Scanner;
public class Sum
public static void main(String args[])
int num1, num2, sum = 0;
Scanner inp = new Scanner(System.in);
System.out.println("\f Program to perform addition");
System.out.println("Enter the first number:");
num1 = inp.nextInt();
System.out.println("Enter the second number:");
num2 = inp.nextInt();
sum = num1+num2;
System.out.println("Sum of Given numbers is :"+sum);
2
OUTPUT-
3
2.Program to print Fibonacci series with and without
recursion.
/** Program to print fibonacci series with and without recursion */
import java.util.Scanner;
public class Series
{ static int temp1=0, temp2=1, temp3=0;
static void Rec_series(int count){
if(count>2){
temp3=temp1+temp2;
temp1=temp2;
temp2=temp3;
System.out.print(" "+temp3);
Rec_series(count-1);
}
}
public static void main(String args[])
{ int count;
Scanner inp = new Scanner(System.in);
System.out.println("\f Program to print fibonacci series");
System.out.println("Enter number of terms");
count= inp.nextInt();
System.out.println("The fibonacci series upto "+count+" terms -");
System.out.print(0+" "+1); // to print the starting 0 and 1
for(int i=2;i<count;++i)
{ temp3=temp1+temp2;
System.out.print(" "+temp3);
temp1=temp2;
temp2=temp3;
}
//Again initializing temp1 . temp2, temp3
temp1=0; temp2=1; temp3=0;
System.out.println("\n\nThe fibonacci series upto "+count+" terms using recurssion -");
System.out.print(0+" "+1);// to print the starting 0 and 1
Rec_series(count); }}
4
OUTPUT-
5
3.Program to check prime numbers
/**
Program to check prime
*/
import java.util.Scanner;
public class Prime
public static void main(String args[])
{ int temp;
boolean flag=true;
System.out.println("\fProgram to check prime numbers");
Scanner inp= new Scanner(System.in);
System.out.println("Enter the number:");
int num=inp.nextInt();
for(int i=2;i<=num/2;i++)
{ temp=num%i;
if(temp==0)
{ flag=false;
break;
}
if(flag==true)
{ System.out.println("Given number is a prime number ");
else{
System.out.println("Given number is not a prime number "); }
6
OUTPUT-
7
4.Program to check palindrome number.
/**
Program to check palindrome
*/
import java.util.Scanner;
public class Palindrome
{
public static void main(String args[])
{
int temp, num1, num2=0, a;
Scanner inp = new Scanner(System.in);
System.out.println("\f Program to check Palindrome");
System.out.println("Enter the number :");
num1= inp.nextInt();
temp= num1;
while(temp>0){
a=temp%10;
num2=(num2*10)+a;
temp=temp/10;
}
if(num2==num1)
{ System.out.println("Given number is a palindrome number ");
}
else{
System.out.println("Given number is not a palindrome number "); }
}
}
8
OUTPUT-
9
10