You are on page 1of 6

IUBAT – International University of

Business Agriculture and Technology.

Lab Report – 02
Course Code: CSC-384
Course Name: Programming In Java Lab

Submitted to:
Naeem Mia
Lecturer, Department of Computer Science and
Engineering.

Submitted by:
Name: Sabbir Hossain
ID: 22103119
Section: F
Semester: Spring -2024
Program: BCSE
Submission Date: 17-02-2024
Experiment :1
Objective: Finding the total amount after 6 months with interest without using
any loop.

Algorithm:
• Import the necessary Java utilities package.
• Define a class named LabTask1.
• Declare the main method within the LabTask1 class.
• Create a Scanner object named 'input' to read user input from the console.
• Display a prompt asking the user to enter their salary.
• Read and store the user's salary as a double variable named 'salary'.
• Define a constant variable 'interest' with the value 1 + 0.004875.
• Calculate the salary after the first month by multiplying the salary with the
'interest' and store it in 'salaryAfterFirstMonth'.
• Repeat steps 8 for the second, third, fourth, fifth, and sixth months, updating
the 'salary' variable each time.
• Calculate 'salaryAfterSecondMonth'
• Calculate 'salaryAfterThirdMonth'
• Calculate 'salaryAfterFourthMonth'
• Calculate 'salaryAfterFifthMonth'
• Calculate 'salaryAfterSixthMonth'
• Display the final calculated salary after the sixth month to the user.
Code:

package labtask;
import java.util.*;
public class LabTask1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter your salary : ");


double salary = input.nextDouble();

double interest = 1 + 0.004875;

double salaryAfterFirstMonth = salary * interest ;


double salaryAfterSecondMonth = (salary + salaryAfterFirstMonth) * interest ;
double salaryAfterThirdMonth = (salary + salaryAfterSecondMonth) * interest ;
double salaryAfterFourthMonth = (salary + salaryAfterThirdMonth) * interest ;
double salaryAfterFifthMonth = (salary + salaryAfterFourthMonth) * interest ;
double salaryAfterSixthMonth = (salary + salaryAfterFifthMonth) * interest ;

System.out.println("Your Balance is : "+salaryAfterSixthMonth );

}
}
Output:

Experiment :2

Objective: The objective of the code is to generate a right-angled triangular


pattern where each row contains sequential numbers, starting from 1 and
incrementing in each subsequent row.
Algorithm:
• Define a class named LabTask4.
• Declare the main method within the LabTask4 class.
• Initialize integer variables 'n' to 1 and 'r' to 5.
• Use a nested loop with an outer loop ranging from 1 to 'r' (inclusive) to
represent rows.
• Inside the outer loop, use an inner loop ranging from 1 to the current value of
the outer
loop variable 'i'.
• Within the inner loop, print the value of 'n' followed by two spaces.
• Increment the value of 'n' after printing each number.
• Print a newline after completing each row to move to the next line.
• Repeat steps 5-6 for each row until the outer loop completes its iterations.
• The output will be a right-angled triangular pattern with sequentially increasing
numbers in each row.

Code:
package LabTask;
public class LabTask4 {
public static void main(String[] args) {
int n =1;
int r=5;
for (int i = 1; i<=r ; i++)
{

for (int j=1; j<=i; j++)


{
System.out.print ("" +n +" ");
n++;

}
System.out.println();
}
}
}

Output:

You might also like