Document X
Document X
Assignment
NAME: SUBHADIP SARKAR
CLASS:IX
UNIQUE ID:
SCHOOL CODE:WB422
YEAR:2024-2025
Acknowledgement
I would like to thank my computer
teacher as well as our Principal mam
who gave me pleasure to do
fantastic project which also enlarged
my knowledge and I was able to
know many things. I am really
thankful to them.
Page:4
18 Inputting number of lines 48-49
and printing the following
structure:
A
AB
ABC
ABCD
19 Program to check whether 50-52
the number is a pronic
number or not
20 Program to check whether 53-55
the number is a Special
number or not
21 Program to find whether 56-58
the number is a spy
number or not
22 Conclusion 59
23 Bibliography 60
Page :5
Introduction
Java is an object-oriented language .It was
developed at Sun Microsystems in 1995.Java
evolved from programming language called
OAK.
Java is simple, case sensitive, object oriented
,platform
independent ,.secure ,robust ,multithreaded
and distributed language .Due to all these
features .Java is used worldwide for various
purposes .Its has many advantages and some
disadvantages.
We can work in java with the help of an IDE.
BlueJ is an IDE which is designed for
beginners. It was designed
By the BlueJ team at Deakin
University ,Melbourne, Australia ,and the
university of kent at Canterbury ,UK .It has a
built in editor ,debugger and viewer. it is a
GUI.
Page:6
Q.2) converting celsius in fahrenheit:
import java.util.*;
class celsiusToFarenheit
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter celsius
value=");
float celsius=sc.nextFloat();
float Fahrenheit=(celsius*9/5)+32;
System.out.println("the Fahrenheit
value is = "+ Fahrenheit);
}
}
Page:7
Output:
Page:8
Q.3)checking if a number is prime
number or not:
import java.util.Scanner;
class check_for_prime_num
{
public static void main(String args[])
{
int n, count=0;
System.out.print("Enter any Number ");
Scanner r=new Scanner(System.in);
n=r.nextInt();
for(int i=1; i<=n; i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
System.out.print("Prime Number");
}
else
{
System.out.print("Not Prime Number");
}
}
}
Page:9
Output:
Enter any number
6
Not Prime
Number
Enter any number
3
Prime Number
Page:10
Q.4) Swapping values of two variable
with using third variable
Import java.util.Scanner;
Class Swap
{
Public static void main(String[] args) {
Int a,b;
System.out.print(“Enter any two Numbers
“);
Scanner ref=new Scanner(System.in);
A=ref.nextInt();
B=ref.nextInt();
System.out.println(“Before Swapping
“+a+” “+b);
A=a+b;
B=a-b;
A=a-b;
System.out.println(“After Swapping
“+a+” “+b);
}
}
Page:11
Output:
Enter any two
numbers 56
64
Before swapping 56
64
After swapping 64
56
Page:12
Q.5)Checking if a year is leap year or
not:
import java.util.Scanner;
class LeapYear
{
public static void main(String[] args) {
System.out.print("Enter your year:");
Scanner sc=new Scanner(System.in);
int year=sc.nextInt();
if(year%400==0||year%4==0)
{
System.out.println("This year is leap
year.");
}
else
{
System.out.println("This year is not a
leap year.");
}
}
}
Page:13
Output:
Enter your year:2020
This year is leap year
Page:15
Output:
Enter the percentage of marks
scored:99
Grade A
Page : 16
Q.7)Performing an arithmetic operation on
two numbers based on the symbol of the
operator entered:
import java.util.Scanner;
double result = 0;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
System.out.println("Error:
Division by zero!");
return;
}
break;
default:
System.out.println("Error: Invalid
operator!");
return;
}
Page:19
Q.8)Calculating the factorial of a number
inputted by the user:
import java.util.Scanner;
long factorial =
calculateFactorialRecursive(num);
System.out.println("Factorial of " + num
+ " is " + factorial);
}
Page:20
Output:
Enter a number:5
Factorial of 5 is 120
Page:21
Q.9)Displaying the Fibonacci series up to a
given number of terms:
import java.util.Scanner;
public class FibonacciSeries {
public static void main(String[] args) {
Scanner scanner = new
Scanner(System.in);
System.out.print("Enter the number of
terms: ");
int numTerms = scanner.nextInt();
scanner.close();
int t1 = 0, t2 = 1;
System.out.print("Fibonacci Series: ");
for (int i = 1; i <= numTerms; ++i) {
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Page:22
Output:
Enter the number of terms:8
Fibonacci series:0+1+1+2+3+5+8+13+
Page:23
Q.10)Reversing the digits of a number:
public class ReverseNumber {
public static int reverse(int num) {
int reversed = 0;
while (num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
return reversed;
}
Page:24
Output:
Original:12345
Reversed:54321
Page:25
Q.11)Menu-driven program to calculate and
print the sum of the following series:
i)S=1/2+2/3+3/44/55/6+…n
import java.util.Scanner;
Page:26
Output:
Enter the number in terms(n):1
The sum of the series is:0.5
Page:27
ii)S=2/4+4/6+6/8+8/10+10/12+….n
public class SeriesSum {
Page:28
Output:
The sum S for n = 10 is:
3.5500000000000003
Page:29
Q.12)Calculate and print the series:
i)S=x/2+x/5+x/8+…..+x/20
public class SeriesSum {
public static void main(String[] args) {
double x = 10; // Example value for x
double sum = calculateSum(x);
System.out.println("The sum S is: " +
sum);
}
return sum;
}
}
Page:30
Output:
The sum S is: 10.961611917494269
Page:31
Q.13)Display the following patterns:
i) 54321
4321
321
21
1
21
321
4321
54321
Page:32
public class NumberPattern {
public static void main(String[] args)
{
int n = 5; // You can change this
value to generate a larger or smaller
pattern
Page:35
Output
*
**
***
****
*****
Page:36
Q.14)Displaying the Floyd’s triangle:
public class FloydsTriangle {
public static void main(String[] args)
{
int rows = 5; // Number of rows in
Floyd's Triangle
int number = 1; // Starting number
Page:37
Output:
1
23
456
7 8 9 10
Page:38
Q.15)Program to check whether the is an
armstrong number or not:
import java.util.Scanner;
Page:40
Output:
Page:41
Q.16)Program to check whether the number
is a niven number or not:
import java.util.Scanner;
Page:43
Q.17)Program to check whether the number
is palindrome or not:
import java.util.Scanner;
return originalNumber ==
reversedNumber; // Check if original and
reversed are the same
}
}
Page:46
Q.18)Inputting number of lines and printing
the following structure: A
AB
ABC
ABCD
public class LetterPattern {
public static void main(String[] args)
{
int n = 4;
// Generate the pattern
for (int i = 1; i <= n; i++) {
for (char j = 'A'; j < 'A' + i; j++) {
System.out.print(j);
}
System.out.println(); // Move to
the next line
}
}
}
Page:48
Output:
A
AB
ABC
ABCD
Page:49
Q.19)Program to check whether the number
is a pronic number or not:
public class PronicNumberChecker {
/**
* Checks if a number is a pronic
number.
*
* @param num the number to check
* @return true if the number is
pronic, false otherwise
*/
public static boolean isPronic(int
num) {
int i = 0;
while (true) {
i++;
int pronic = i * (i + 1);
if (pronic == num) {
return true;
} else if (pronic > num) {
return false;
}
}
}
Page:51
Output:
20 is a pronic number.
Page:52
Q.20)Program to check whether the number
is a Special number or not
public class SpecialNumber {
public static boolean isSpecial(int
num) {
int sum = 0;
int temp = num;
while (temp != 0) {
int digit = temp % 10;
sum += factorial(digit);
temp /= 10;
}
return sum == num;
}
Page:54
Q.21)Program to find whether the number is
a spy number or not:
import java.util.Scanner;
Page:57
Output:
Enter a number: 112
112 is not a spy number.
Enter a number: 123
123 is a spy number.
Page:58
Conclusion
Java is one of the most popular and in-demand
programming languages to learn and it was one of
the first languages to standardize high-level
threading utilities.
Page:59
Bibliography
Websites
www.javapoint.com
www.geeksforgeeks.c
om
Books
Computer Applications
with Blue) for Class
9(ICSE)
Enter a number:66
66 is not a niven number.
Page:44
Output:
Enter a number: 99
99 is a palindrome
Enter a number: 24
24 is not a palindrome.
Page:47