Professional Documents
Culture Documents
Lab Report – 03
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: The objective of the program in Java is to prompt the user to input a
positive integer and then count the occurrences of the digit '2' in that number.
Algorithm:
• It starts by declaring variables for the user input ('n') and the result of the
digit counting function ('result').
• It prompts the user to input a number, reads the input, and checks if it's
greater than 0.
• If the number is positive, it calls the test function to count the occurrences
of the digit '2' and displays the result.
• The test function takes an integer parameter, initializes a counter ('ctr'),
and iterates through each digit of the number, incrementing the counter if
the digit is '2'.
• The final count is returned.
Code:
package my.userinput;
import java.util.Scanner;
public class intValue2 {
}
Output:
Experiment :2
Code:
package my.userinput;
import java.util.Scanner;
Output: