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 [Link];
public class Sum
public static void main(String args[])
int num1, num2, sum = 0;
Scanner inp = new Scanner([Link]);
[Link]("\f Program to perform addition");
[Link]("Enter the first number:");
num1 = [Link]();
[Link]("Enter the second number:");
num2 = [Link]();
sum = num1+num2;
[Link]("Sum of Given numbers is :"+sum);
2
OUTPUT-
3
[Link] to print Fibonacci series with and without
recursion.
/** Program to print fibonacci series with and without recursion */
import [Link];
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;
[Link](" "+temp3);
Rec_series(count-1);
}
}
public static void main(String args[])
{ int count;
Scanner inp = new Scanner([Link]);
[Link]("\f Program to print fibonacci series");
[Link]("Enter number of terms");
count= [Link]();
[Link]("The fibonacci series upto "+count+" terms -");
[Link](0+" "+1); // to print the starting 0 and 1
for(int i=2;i<count;++i)
{ temp3=temp1+temp2;
[Link](" "+temp3);
temp1=temp2;
temp2=temp3;
}
//Again initializing temp1 . temp2, temp3
temp1=0; temp2=1; temp3=0;
[Link]("\n\nThe fibonacci series upto "+count+" terms using recurssion -");
[Link](0+" "+1);// to print the starting 0 and 1
Rec_series(count); }}
4
OUTPUT-
5
[Link] to check prime numbers
/**
Program to check prime
*/
import [Link];
public class Prime
public static void main(String args[])
{ int temp;
boolean flag=true;
[Link]("\fProgram to check prime numbers");
Scanner inp= new Scanner([Link]);
[Link]("Enter the number:");
int num=[Link]();
for(int i=2;i<=num/2;i++)
{ temp=num%i;
if(temp==0)
{ flag=false;
break;
}
if(flag==true)
{ [Link]("Given number is a prime number ");
else{
[Link]("Given number is not a prime number "); }
6
OUTPUT-
7
[Link] to check palindrome number.
/**
Program to check palindrome
*/
import [Link];
public class Palindrome
{
public static void main(String args[])
{
int temp, num1, num2=0, a;
Scanner inp = new Scanner([Link]);
[Link]("\f Program to check Palindrome");
[Link]("Enter the number :");
num1= [Link]();
temp= num1;
while(temp>0){
a=temp%10;
num2=(num2*10)+a;
temp=temp/10;
}
if(num2==num1)
{ [Link]("Given number is a palindrome number ");
}
else{
[Link]("Given number is not a palindrome number "); }
}
}
8
OUTPUT-
9
10