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

python and DBMS

Uploaded by

kumar00vishal00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

python and DBMS

Uploaded by

kumar00vishal00
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Experiment Number WEEK1 LAB1

Date of Experiment 11/01/2024

Date of Submission 18/01/2024

Name of student SANJAY PATEL

Roll Number 2230041

Section ECSc-1

 Title of the Experiment:


Introduction to Java

 Aim of the Experiment:

1. To learn writing, executing and debugging programs related to basic I/O functions.
2. To learn writing, executing and debugging programs related to arithmetic operators.
 Programming Language used:
Java

 Problem Statement & Solution:


1. Write a Java program to print the following on the console: “Name”
“Roll number”
“Branch”
“Department”
“University”

SOL:-
class Prog1{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Branch: ECSc");
System.out.println("Department: Electronics");
System.out.println("University: KIIT University");
}}

2. Write a Java program to find the area and circumference of a circle, given
its radius, r.

SOL:
class Prog2{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
int r=3;
float area=3.14f*r*r;
float circumference=2*3.14f*r;
System.out.println("Area of the circle:"+area);
System.out.println("Circumference of the circle:"+circumference);
}}

3. Write a Java program to accept the length and breadth of a rectangle and
display its area and perimeter.

SOL:
class Prog3{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
int l=12, b=10;
float area=l*b;
float perimeter=2*(l+b);
System.out.println("Area of the rectangle:"+area);
System.out.println("Perimeter of the rectangle:"+perimeter);
}}

4. Write a Java program to accept the number of seconds and display its
equivalent number of hours, number of minutes and number of seconds (Hint:
Use / and % operators).
SOL:
import java.util.Scanner;
class Prog4{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Enter Seconds");
Scanner sc= new Scanner(System.in);
int seconds=sc.nextInt();
int hours=seconds/3600;
int minutes=(seconds%3600)/60;
int sec=(seconds%3600)%60;
System.out.println("TIME="+hours+"h:"+minutes+"min:"+sec+"sec");
}}

 Output:
OUTPUT 1:-

OUTPUT 2:-

OUTPUT 3:-
OUTPUT 4:-

 Conclusion:
Learned to develop and execute basic Java programs .

_________________

Faculty Signature
Experiment Number WEEK 1 LAB 2

Date of Experiment 12/01/2024

Date of Submission 18/01//2024

Name of student SANJAY PATEL

Roll Number 2230041

Section ECSc-1

 Title of the Experiment:


Operators, Selectors and Iterators
 Aim of the Experiment:
 To learn writing, executing and debugging programs related to Java operators.
 To learn writing, executing and debugging programs related to Java decision control and
loop control statements.
 Programming Language used:
Java

 Problem Statement & Solution:


1. Write a Java program to print a table of values of the function y = e−x
for x varying from 0 to 1 in steps of 0.1. The table appears as follows.
x 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
y

SOL:
import java.lang.Math;
class Prog1{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
double x,y;
for(x=0;x<=1;x=x+0.1){
y=Math.exp(-x);
x=Math.floor(x*100)/100;
y=Math.floor(y*1000)/1000;
System.out.println("If X= "+x+" then Y= "+y);
}}}

2. Write a Java program to find the largest of three numbers using a conditional operator.

SOL:
import java.util.Scanner;
class Prog2{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Enter three numbers");
Scanner sc= new Scanner(System.in);
int first =sc.nextInt();
int second =sc.nextInt();
int third=sc.nextInt();
int largest=(first>second)?(first>third?first:third):(second>third?second:third);
System.out.println("Largest Number is "+largest);
}}

3. Write a Java program to accept a point (x, y) and find whether it lies on the circle or
inside the circle or outside the circle. The center of the circle is (0, 0) and the radius of the
circle is 5. Equation of a circle with (0, 0) as the center and r as the radius is given by x2 +
y2 = r2.
1. If x2 + y2 < r2, then the point (x, y) lies within the circle.
2. If x2 + y2 > r2, then the point (x, y) lies outside the circle.
3. If x2 + y2 = r2, then the point (x, y) lies on the circle.
SOL:
import java.util.Scanner;
class Prog3{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Enter Coordinates of the point");
Scanner sc= new Scanner(System.in);
int r=5;
int x =sc.nextInt();
int y =sc.nextInt();
if((x*x)+(y*y)>(r*r)){
System.out.println("point (x, y) lies within the circle ");}
else if((x*x)+(y*y)<(r*r)){
System.out.println("point (x, y) lies outside the circle.");}
else{
System.out.println("point (x, y) lies on the circle.");}
}}

4. Write a Java program to find whether a number is an Armstrong number


or not. (Hint: A number is an Armstrong number if the sum of the cubes
of the digits of the number is equal to the number itself. For example,
153 = 13 + 53 + 33 = 1 + 125 + 27).

SOL:
import java.util.Scanner;
import java.lang.Math;
class Prog4{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Enter the Number");
Scanner sc= new Scanner(System.in);
int num =sc.nextInt();
int a,x,count=0;
double sum=0;
x=num;
while(num!=0){
count=count+1;
num=num/10;}
num=x;
for(int i=0;i<count;i++){
a=num%10;
sum=sum+Math.pow(a,count);
num=num/10;}
if(x==sum){
System.out.println("Number is armstrong number");}
else{
System.out.println("Number is not armstrong number");}
}}

5. Write a Java program to generate a Fibonacci series.


SOL:-
import java.util.Scanner;
import java.lang.Math;
class Prog5{
public static void main(String args[])
{
System.out.println("Name: Sanjay Patel");
System.out.println("Roll: 2230041");
System.out.println("Enter the Number till which to find fibonacci series");
Scanner sc= new Scanner(System.in);
int num =sc.nextInt();
int x=0,y=1,z;
System.out.print("Fibonacci Series: ");
System.out.print(x);
for(int i=0;i<num;i++){
z=x+y;
x=y;
y=z;
System.out.print(" "+x);}
}}
 Output:
OUTPUT
1:

OUTPUT 2:

OUTPUT 3:

OUTPUT 4:-
OUTPUT 5:-

 Conclusion:
Learned to develop and execute Java programs using operators, if-else, for loop, etc.

_________________

Faculty Signature

You might also like