0% found this document useful (0 votes)
2 views10 pages

Class - IX First Term Project Solution

The document contains a series of Java programming exercises for Class IX, including algorithms and code for various tasks such as displaying messages, performing arithmetic operations, calculating areas of geometric shapes, and displaying number sequences. Each task is structured with a clear algorithm followed by the corresponding Java program. The exercises aim to enhance students' understanding of basic programming concepts and Java syntax.

Uploaded by

razoopatel92
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Class - IX First Term Project Solution

The document contains a series of Java programming exercises for Class IX, including algorithms and code for various tasks such as displaying messages, performing arithmetic operations, calculating areas of geometric shapes, and displaying number sequences. Each task is structured with a clear algorithm followed by the corresponding Java program. The exercises aim to enhance students' understanding of basic programming concepts and Java syntax.

Uploaded by

razoopatel92
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Class – IX

First Term Project Solution


1. WAP for displaying simple message “Hello World”.

Algorithm:

Step 1: Start
Step 2: Display "Hello World"
Step 3: Stop
Program:
class Hello
{
public static void main(String args[])
{
[Link]("Hello World");
}
}
2. WAP for adding two values using Scanner Method.

Algorithm:

Step 1: Start
Step 2: Input first number a
Step 3: Input second number b
Step 4: Calculate sum = a + b
Step 5: Display sum
Step 6: Stop

Program:

import [Link].*;

class Add
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int a,b,sum;

[Link]("Enter first number:");


a=[Link]();

[Link]("Enter second number:");


b=[Link]();
sum=a+b;

[Link]("Sum="+sum);
}
}

3. WAP for multiplying three values.

Algorithm:

Step 1: Start
Step 2: Declare values a, b, c
Step 3: Calculate mul = a × b × c
Step 4: Display multiplication result
Step 5: Stop

Program:

class Multiply
{
public static void main(String args[])
{
int a=2,b=3,c=4,mul;

mul=a*b*c;

[Link]("Multiplication="+mul);
}
}

4. WAP for adding two values using runtime input.

Algorithm:

Step 1: Start
Step 2: Read two numbers from command line
Step 3: Calculate sum = a + b
Step 4: Display sum
Step 5: Stop

Program:

import [Link];

public class AddTwoNumbers {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter first number: ");

int a = [Link]();

[Link]("Enter second number: ");

int b = [Link]();

int sum = a + b;

[Link]("The sum of " + a + " and " + b + " is: " + sum);

5. WAP for multiplying four values using run time input.

Algorithm:

Step 1: Start
Step 2: Read four numbers from command line
Step 3: Calculate mul = a × b × c × d
Step 4: Display multiplication result
Step 5: Stop

Program:

import [Link];

public class MultiplyFour {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter first number: ");

int a = [Link]();

[Link]("Enter second number: ");

int b = [Link]();

[Link]("Enter third number: ");

int c = [Link]();

[Link]("Enter fourth number: ");


int d = [Link]();

int mul = a * b * c * d;

[Link]("The Multiplication of 4 numbers are: " + mul);

6. WAP for finding area of circle.

Algorithm:

Step 1: Start
Step 2: Input radius r
Step 3: Calculate area = 3.14 × r × r
Step 4: Display area
Step 5: Stop
Program:
import [Link].*;

class Circle
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

double r,area;

[Link]("Enter radius:");
r=[Link]();

area=3.14*r*r;

[Link]("Area="+area);
}
}

7. WAP for finding area of triangle.

Algorithm:

Step 1: Start
Step 2: Input base b and height h
Step 3: Calculate area = (b × h) / 2
Step 4: Display area
Step 5: Stop

Program:
import [Link].*;

class Triangle
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

double b,h,area;

[Link]("Enter base:");
b=[Link]();

[Link]("Enter height:");
h=[Link]();

area=(b*h)/2;

[Link]("Area="+area);
}
}

8. WAP for finding area of rectangle.

Algorithm:

Step 1: Start
Step 2: Input length l and breadth b
Step 3: Calculate area = l × b
Step 4: Display area
Step 5: Stop

Program:

import [Link].*;

class Rectangle
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int l,b,area;

[Link]("Enter length:");
l=[Link]();

[Link]("Enter breadth:");
b=[Link]();
area=l*b;

[Link]("Area="+area);
}
}

9. WAP for finding area of square.

Algorithm:

Step 1: Start
Step 2: Input side s
Step 3: Calculate area = s × s
Step 4: Display area
Step 5: Stop

Program:

class Square
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int s,area;

[Link]("Enter side:");
s=[Link]();

area=s*s;

[Link]("Area="+area);
}
}

10. WAP for finding greatest value among three values.

Algorithm:

Step 1: Start
Step 2: Input a, b, c
Step 3: Compare all values
Step 4: Find greatest number
Step 5: Display greatest value
Step 6: Stop
Program:
import [Link].*;

class Greatest
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int a,b,c;

[Link]("Enter three numbers:");


a=[Link]();
b=[Link]();
c=[Link]();

if(a>b && a>c)


[Link](a+" is greatest");
else if(b>a && b>c)
[Link](b+" is greatest");
else
[Link](c+" is greatest");
}
}

11. WAP for displaying odd numbers

Algorithm:

Step 1: Start
Step 2: Set i = 1
Step 3: Repeat until i ≤ 20
Step 4: Display i
Step 5: Increase i by 2
Step 6: Stop

Program:

class Odd
{
public static void main(String args[])
{
for(int i=1;i<=20;i+=2)
{
[Link](i);
}
}
}
12. WAP for displaying even numbers.

Algorithm:

Step 1: Start
Step 2: Set i = 2
Step 3: Repeat until i ≤ 20
Step 4: Display i
Step 5: Increase i by 2
Step 6: Stop

Program:

class Even
{
public static void main(String args[])
{
for(int i=2;i<=20;i+=2)
{
[Link](i);
}
}
}

13. WAP for displaying multiplication table.

Algorithm:

Step 1: Start
Step 2: Input number n
Step 3: Repeat from 1 to 10
Step 4: Calculate n × i
Step 5: Display result
Step 6: Stop

Program:

import [Link].*;

class Table
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int n;

[Link]("Enter number:");
n=[Link]();
for(int i=1;i<=10;i++)
{
[Link](n +” * ”+i + “ = ”+ n*i);
}
}
}

14. WAP for performing sum of n numbers.

Algorithm:

Step 1: Start
Step 2: Input value n
Step 3: Set sum = 0
Step 4: Add numbers from 1 to n
Step 5: Display sum
Step 6: Stop

Program:

import [Link].*;

class SumN
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int n,sum=0;

[Link]("Enter value:");
n=[Link]();

for(int i=1;i<=n;i++)
{
sum=sum+i;
}

[Link]("Sum="+sum);
}
}

15. WAP for swapping two values.

Algorithm:

Step 1: Start
Step 2: Input values a and b
Step 3: Store a in temp
Step 4: Assign b to a
Step 5: Assign temp to b
Step 6: Display swapped values
Step 7: Stop

Program:

import [Link].*;

class Swap
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);

int a,b,temp;

[Link]("Enter two numbers:");


a=[Link]();
b=[Link]();

temp=a;
a=b;
b=temp;

[Link]("After swapping:");
[Link]("a="+a);
[Link]("b="+b);
}
}

You might also like