0% found this document useful (0 votes)
19 views7 pages

AnshM 9DCA Term2Project

20 programs on common qs in java with outputs and variable description tables
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)
19 views7 pages

AnshM 9DCA Term2Project

20 programs on common qs in java with outputs and variable description tables
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
You are on page 1/ 7

COMPUTER PROJECT

Term 2

Grade: 9D

Roll No. 18

9D
PROGRAM 1

Question 1:
Write a menu driven program to

•display the largest as well as the smallest integer amongst all the integers entered.

•find the sum of two-digit as well as three-digit numbers separately for all the integers entered.

Take the number of integers and the integers as input from the user.

Code:
import java.util.Scanner;

public class CA_Project_Term2

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("How many numbers do you wanto to enter? ");

int n = sc.nextInt();

int high=0;

int low =5;

int sum2 = 0;

int sum3 = 0;

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

System.out.println("Enter the " + i + " number: ");


int num = sc.nextInt();

if(i==1)

high = num;

low = num;

if(num>=high)

high = num;

if(num<=low)

low=num;

if(num<=999 && num>=100)

sum3= sum3+num;

if(num>=10 && num<=99)

sum2 = sum2 +num;

System.out.println("Enter \'1\' to view the smallest and biggest number in the integers and \n\'2\' to find the sum of all 2 digit and 3 digit
numbers separately");

int ch = sc.nextInt();

switch(ch)

case 1:

System.out.println("The Lowest Number Is: " + low);

System.out.println("The Highest Number Is: " + high);

break;

case 2:

System.out.println("The Sum Of All 2 Digit Numbers Is: " + sum2);

System.out.println("The Sum Of All 3 Digit Numbers Is: " + sum3);

break;
default:

System.out.println("Invalid Input Entered");

Output:

Case 1 Case 2

Variable Description Table

Variable Name Date Type Purpose


n int For storing value of number of
values being entered by user
high int To store value of highest value
among integers
low int To store value of lowest value
among integers
sum2 int To store value of sum of all 2
digit numbers
sum3 int To store value of sum of all 3
digit numbers
num int To store values of numbers
enterd by user
ch int To store choice of user
PROGRAM 2

Question 2:
Write a menu driven program to find the sum of following series

i)s=1*3 + 2*4 + 3*5 +....... + 6*8 + 7*9 +....... m*n (Take m and n as input from user)

ii)s= 1 − 1/2 + 1/3 − 1/4 + 1/5……………….±1/m (Take m as input from user)

Code:
import java.util.Scanner;

public class CA_Project_Term2_Prgm2

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Enter '1' for the first sum series and '2' for the second sum series");

int ch = sc.nextInt();

double sum;

int m,n;

switch(ch)

{
case 1:

System.out.println("Enter the value of \'m\' and \'n\': ");

m = sc.nextInt();

n = sc.nextInt();

sum = 0;

for(int i =1, j=3; i<=m; i++, j++)

sum = sum + (i*j);

System.out.println("The answer of the sum series is: " + sum);

break;

case 2:

sum = 0;

System.out.println("Enter the value of \'m\' : ");

m = sc.nextInt();

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

if(i%2!=0)

sum = sum + (double)(1/i);

else

sum = sum - (double)(1/i);

System.out.println("The answer of the sum series is: " + sum);

break;

default:

System.out.println("Invalid Input Entered");

}
Output:

Case 1 Case 2

Variable Description Table

Variable Name Date Type Purpose


ch int For storing the choice of the user
sum double To store value sum of the series
through successive passes of the
loop
m int To store value of m entered by
the user
n int To store value of n entered by
the user

You might also like