You are on page 1of 9

CSE 215L: Programming Language

II Lab
Faculty: Silvia Ahmed,
Sec – 9,10
Lab 4 – Spring 2021
Task 01
• Take a number as input (for example num)
• In the main method run a loop from 1 to num and inside the
loop, call the method like this: getPentagonalNumber(num)
and print the output.
• Outside the main method define the method using return n(3n–
1)/2
Task 02
• Take input in the main method and invoke the sumDigits(long
n) method.
• Inside the sumDigits(long n) method, uses the loop fro
extracting digits of a number and finding sum.
• Print the result inside the main method.
Task 03
• Take input in the main method and invoke the
isPalindrome(int number) method.
• Inside isPalindrome(int number), invoke reverse(int number)
and store in a variable (for example num1). Compare number
with the reverse number and return true or false.
Task 04 & Task 05
• Take input in the main method.
• Invoke the method and print the result inside your method
using loop.
Task 06
• Take input in the main method.
• Invoke the method.
• Inside the method, use (int)(Math.random() * 2) to generate a
number and print them n per line.
Task 07
• Take input in the main method.
• Invoke the method isValid(double side1, double side2,
double side3) if it returns true then invoke area(double side1,
double side2, double side3).
• Inside area(double side1, double side2, double side3) use the
formula and return the result and print it in the main method.
Task 08
• Take different variables for hours, minutes and seconds.
• use hours + “:” + minutes +”:” + seconds to print.
Task 09
• The formula is for pentagon and you need to take the side as
user input.
• Use n = 5 by default for the method area(int n, double side).
• Use the formula inside the method and print result.

You might also like