Computer Project Class9(Amsc)
Computer Project Class9(Amsc)
1. Write a program to input three positive numbers, then check they are Pythagorean triplet or not. *USE if-
else + , hints : If x>y and x>z and x*x = y*y + z*z.
import java.util.Scanner;
class PythagorasCheck
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.print("Pythagorean triplet");
System.out.print("Pythagorean triplet");
System.out.print("Pythagorean triplet");
else
else
2. Write a program to ask the user to enter the year to check whether it is a century leap year or not. * Use if-
else +
import java.util.Scanner;
class LeapYearCheck
if (year % 400 == 0)
else
else
3 . Wap to input a number within 0 to 99 .Print the number in words (Use Switch Case) Example 1 : Input 19 Example 1
: Input 93
import java.util.*;
class NumberToWords
System.out.println("Enter A Number:");
int no=sc.nextInt();
If(no==0)
System.out.print(“Zero “);
switch(no)
else
switch(no/10)
switch(no%10)
4. Write a program to input principal amount, rate of interest and number of years. Then input choice from user . 1)
Simple interest 2) Compound interest .
Calculate simple interest or compound interest by using the following formulae. Amount of Simple Interest. Si=p* r*
t/100 ;
P* 1 + ( r /100)+ t – P
import java.util.Scanner;
class InterestCalculator
,
Scanner sc = new Scanner(System.in);
double interest = (choice == 1) ? (principal * rate * time) / 100 .0 : (Math.pow((1 + rate / 100), time) * principal -
principal);
5. Write a program to input total cost of books purchased by a customer. Then calculate discount as per the following
rules. Finally calculate and print payable amount of the customer. Add 6.5% of payable amount as tax along with the
payable amount.
import java.util.Scanner;
class BookBill ,
double tc = sc.nextDouble();
double d;
if (tc <= 1000)
d = tc * 0.07;
d = tc * 0.10;
else
d = tc * 0.20;
double pa = tc - d;
double tx = pa * 0.065;
double ta = pa + tx;
6. Write a program to calculate electricity bill. Enter meter reading of previous month and current month. Find out
how much unit of electricity were consumed by the customer. Then calculate the bill by using the following rules.
Input age of the person.
Charge Rs 800 as the rent of meter machine. In calculated bill add 14.5% tax to get final bill. If senior citizen then give
3% discount of final bill.
import java.util.Scanner;
class ElectricityBill ,
double charge = 0;
charge = unit * 3;
- else ,
-
7. Write a program which will input a number. Then it will first check the number is a prime number or not * by for
loop+ . Then it will check the number is palindrome number of not by while loop. Both the task will be done in the
same program one after the other.
class Time
int n = sc.nextInt();
int c = 0;
if ( n % i == 0)
c++;
while ( b > 0 )
d = b % 10 ;
r = r * 10 + d;
b = b / 10;
if ( c == 2 && r == n)
else if ( c == 2 )
else if ( r == n )
,
System.out.print( " Palindrome but not prime ");
else
8. Write a program to print first n terms of the Fibonacci series by for loop. Print their sum.
Then perform the same task but the terms which are even in Fibonacci series within n terms, only those terms will be
printed ( by while loop ).
import java.util.Scanner;
class FibonacciSeries ,
int n = sc.nextInt();
//Print first n Fibonacci terms using for loop and sum them
int a = 0, b = 1, sum = 0;
sum += a;
int c = a + b;
a = b;
b = c;
a = 0; b = 1;
int count = 1;
if (a % 2 == 0) ,
int c = a + b;
a = b;
b = c;
count++;
9. Write a program to print the following pattern. Full Height will be the input. Use only single loops ( do-while) in this
program.
1234321
111 111
12 21
1 1
12 21
111 111
1234321
import java.util.Scanner;
class Pat,
int n = sc.nextInt();
if (n < 3 || n % 2 == 0) ,
return;
int i = 1;
int mid = (n + 1) / 2;
do ,
int row = (i - 1) / n + 1;
int col = (i - 1) % n + 1;
if (row == 1 || row == n) ,
System.out.print(col);
else
if (col != mid)
System.out.print("1");
else
System.out.print(" ");
if (col == 1 || col == n)
System.out.print("1");
else
System.out.print(" ");
- else ,
if (col == 1 || col == 2)
System.out.print(col);
else
System.out.print(" ");
if (col == n)
System.out.println();
i++;
3. Numbers which is having odd value in unit and tens position in the range 100 to 999
import java.util.Scanner;
class MenuProgram ,
System.out.println("Menu:");
System.out.println("3. Numbers with odd unit and tens digits in the range 100 to 999.");
int a = 0, b = 0;
switch(choice) ,
case 1:
a = sc.nextInt();
if(i % 7 == 0 || i % 10 == 7) ,
break;
case 2:
a = sc.nextInt();
b = sc.nextInt();
if(i % 3 == 0 || i % 5 == 0) ,
break;
case 3:
System.out.println("Numbers between 100 and 999 with odd unit and tens digits:");
System.out.print(i + "\n");
-
break;
default:
System.out.println("Invalid choice!");