Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

Java File

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

Java File

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

Term work

of
Java Programming Lab (PCS-408)
Submitted in partial fulfillment of the requirement for the IV semester

Bachelor of Technology
By
Ajay Rawat

2261076
Under the Guidance of
Ms. Kashish Mirza
Lecturer
Department of CSE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


GRAPHIC ERA HILL UNIVERSITY, BHIMTAL CAMPUS
SATTAL ROAD, P.O. BHOWALI
DISTRICT- NAINITAL-263132
2023-2024
CERTIFICATE

The term work of Java Programming Lab , being submitted by Ajay Rawat

D/O Mr. Surendra Singh Rawat University Roll Number 2261076 to Graphic

Era Hill University, Bhimtal Campus for the award of bona fide work carried

out by him. He has worked under my guidance and supervision and fulfilled

the requirement for the submission of this work report.

(Ms. Kashish Mirza) (Dr. Ankur Singh Bisht)

Lecturer HOD, CSE Dept.


ACKNOWLEDGEMENT

I take immense pleasure in thanking Honorable Ms. Kashish Mirza

(Lecturer, Dept. of CSE, GEHU Bhimtal Campus) for allowing me to carry out

this practical work under his excellent and optimistic supervision. This has all

been possible due to his novel inspiration, able guidance and useful suggestions

that have helped me in developing my subject concepts as a student.

I want to extend thanks to our President Prof. (Dr.) Kamal Ghanshala for

providing us all infrastructure and facilities to work in need without which this

work would not be possible.

(AJAY RAWAT)
University Roll Number: 2261076
INDEX PAGE
S.no. Question Date Sign
01 Write a java program to print “Hello world”
02 Write a java program to add two numbers
03 Write a java program to add two numbers by taking input from user
04 Write a java program to print the difference of two numbers
05 Write a java program to print the difference of two numbers by taking
input from user
06 Write a java program to print a pattern:
*
**
***
****
*****
07 Write a java program to check weather the given number is even or
odd
08 Write a java program to print the string by taking input from user
09 Write a java program to demonstrate switch case statement:
Case 1: “Graphic Era Bhimtal”
Case 2: “Graphic Era Haldwani”
Case 3: “Graphic Era Dehradun”
Case 4: “Graphic Era Deemed To Be University”
default: “GEHU”
10 Write a java program to print two statements in different lines by line
changing method
11 Write a java program to print “hello world” 100 times by using for
loop
12 Write a java program to print natural numbers up to 10
(i) in horizontal form,
(ii) in vertical form by using for loop:
Eg: 1 2 3 4 ….
Eg: 1
2
3..
13 Write a java program to print table of a number by taking input from
user using do while loop
14 Write a java program to print natural numbers up to 11 by using while
loop
15 Write a java program to print the pattern, using nested loop:
****
****
****
****
16 Write a java program to take input as a command line argument.
Your name,course, university roll no and semester. Display the
information.
Name: University Roll No: Course: Semester:
17 Using the switch statement, write a menu-driven program to
calculate thematurity amount of a bank deposit.
The user is given the following options:
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept Principal (p), rate of interest (r) and time period
in years (n). Calculate and output the maturity amount (a) receivable
using the formulaa = p[1 + r / 100]n.

For option (ii) accept monthly installment (p), rate of interest (r) and
time periodin months (n). Calculate and output the maturity amount
(a) receivable using the formula a = p * n + p * n(n + 1) / 2 * r / 100 *
1 / 12. For an incorrect option,an appropriate error message should be
displayed.
[ Use Scanner Class to take input]

18 Program to find if the given numbers are Friendly pair or not


(Amicable ornot). Friendly Pair are two or more numbers with a
common abundance.
Input & Output format:

• Input consists of 2 integers.


• The first integer corresponds to number 1 and the
second integercorresponds to number 2.
If it is a Friendly Pair display Friendly Pair or displays Not Friendly
Pair.

For example,6 and 28 are Friendly Pair.


(Sum of divisors of 6)/6 = (Sum of divisors of 28)/28.
Steps to check whether the given numbers are friendly pair or not

▪ Input the numbers num1 and num2.


▪ Initialize sum1 = sum2 = 0.
▪ sum1 = sum of all divisors of num1.
▪ sum2 = sum of all divisors of num2.
▪ If (sum1 == num1) and (sum2 ==
num2), then print"Abundant Numbers".
▪ Else, print "Not Abundant Numbers".

19 Program to replace all 0's with 1 in a given integer. Given an integer as


an input,all the 0's in the number has to be replaced with 1.
For example, consider the following number Input: 102405
Output: 112415
Input: 56004
Output: 56114
Steps to replace all 0's with 1 in a given integer
• Input the integer from the user.
• Traverse the integer digit by digit.
• If a '0' is encountered, replace it by '1'.
• Print the integer.
20
Printing an array into Zigzag fashion. Suppose you were given an
array of integers, and you are told to sort the integers in a zigzag
pattern. In general, ina zigzag pattern, the first integer is less than the
second
integer, which is greater than the third integer, which is less than the
fourth integer, and so on. Hence, the converted array should be in the
form of e1 < e2
> e3
< e4
> e5
< e6.
Test
cases:
Input
1:7
4378621

Output 1:
3748261

Input 2:
4
1432

Output 2: 1 4 2 3
21 The problem to rearrange positive and negative numbers in an array .
Method: This approach moves all negative numbers to the beginning
and positive numbers to the end but changes the order of appearance
of the elements of the array.
Steps:

1. Declare an array and input the array elements.


2. Start traversing the array and if the current element is
negative, swap the current element with the first
positive element and continue traversing until all the
elements have been encountered.
3. Print the rearranged array.

Test case:

• Input: 1 -1 2 -2 3 -3
• Output: -1 -2 -3 1 3 2
22 Program to find the saddle point coordinates in a given matrix. A
saddle pointis an element of the matrix, which is the minimum
element in its row and the
maximum in its column.
For example, consider the matrix given
below Mat [3][3]1 2 3
456
789
Here, 7 is the saddle point because it is the minimum element in its
row andmaximum element in its column.
Steps to find the saddle point coordinates in a given matrix.

1. Input the matrix from the user.


2. Use two loops, one for traversing the row and
the other fortraversing the column.
3. If the current element is the minimum element in
its row andmaximum element in its column, then
return its coordinates.
Else, continue traversing.
Q1. Write a java program to print “Hello world”.

Import java.util.*;
class HelloWorld{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}

Output: Hello World

You might also like