0% found this document useful (0 votes)
17 views

Project

Uploaded by

ishanaaaaaa189
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Project

Uploaded by

ishanaaaaaa189
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

//wap to enter a no.

and check if it is niven or not


import java.util.*;

class niven

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter a number");

int n=sc.nextInt();

int s=0;

int d=0;

int k=0;

for(int i=n;i!=0;i/=10)

d=n%10;

s=s+d;

if(n%s==0)

System.out.println("it is niven");

else

System.out.println("not niven");

}
//wap to enter a no. and check if it is armstrong or not

import java.util.*;

class Armstrong

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter the no.");

int n=sc.nextInt();

int s=0;

int d=0;

int p=n%10;

for(int i=n;i>0;i/=10)

d=i%10;

s+=Math.pow(d,p);

if(s==n)

System.out.println("armstrong");

else {

System.out.println("not armstrong");

}
// wap to calculate the following series 1/4+2/8+3/12...n

import java.util.*;

public class hwseries2

public static void main(String[] args)

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the value of n: ");

int n = scanner.nextInt();

double sum = 0;

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

sum += i / (4.0 * i);

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

}
//wap to enter a number and check if it is abundant or not
import java.util.*;

class abundant

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter a no.");

int n=sc.nextInt();

int f=0;

int s=0;

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

if(n%i==0)

s=s+i;

if(n<s)

System.out.println("abundant");

else

System.out.println("non abundant");

}
//WAP TO ENTER A CHARACTER AND CHECK IF IT IS A VOWEL OR CONSONANT USING SWITCH
CONSTRUCT

import java.util.*;

class halfyearlyques6

public static void main()

Scanner sc = new Scanner(System.in);

System.out.print("\n Enter Character: ");

char c = sc.next().charAt(0);

char z = Character.toUpperCase(c);

switch (z)

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

System.out.println(c + " is a Vowel.");

break;

default:

System.out.println(c + " is a consonant");

}
//WAP TO ENTER YOUR CHOICE FOR CALCULATING AREA OF CIRCLE,RECTANGLE OR RECTANGLE

import java.util.*;

class ishana333

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.println("Enter c to calculate area of circle");

System.out.println("Enter s to calculate area of square");

System.out.println("Enter r to calculate area of rectangle");

System.out.print("Enter your choice: ");

char choice = in.next().charAt(0);

switch(choice)

case 'c':

System.out.print("Enter radius of circle: ");

double r = in.nextDouble();

double ca = (22 / 7.0) * r * r;

System.out.println("Area of circle = " + ca);

break;

case 's':

System.out.print("Enter side of square: ");

double side = in.nextDouble();

double sa = side * side;

System.out.println("Area of square = " + sa);

break;

case 'r':
System.out.print("Enter length of rectangle: ");

double l = in.nextDouble();

System.out.print("Enter breadth of rectangle: ");

double b = in.nextDouble();

double ra = l * b;

System.out.println("Area of rectangle = " + ra);

break;

default:

System.out.println("Wrong choice!");

}
//wap to enter the temperature and convert it to Fahrenheit to Celsius and vice versa

import java.util.Scanner;

class ishanatemperature

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Type 1 to convert from Fahrenheit to Celsius");

System.out.println("Type 2 to convert from Celsius to Fahrenheit");

int choice = sc.nextInt();

double ft = 0.0, ct = 0.0;

switch(choice)

case 1:System.out.print("Enter temperature in farenheit : ");

ft = sc.nextDouble();

ct = 5 / 9.0 * (ft - 32);

System.out.println("Temperature in celsius : " + ct);

break;

case 2:

System.out.print("Enter temperature in celsius: ");

ct = sc.nextDouble();

ft = 1.8 * ct + 32;

System.out.println("Temperature in farenheit: " + ft);

break;

default:

System.out.println("WRONG CHOICE");

break;

}
// WAP TO ENTER YOUR CHOICE FOR CHECKING IF A NO. IS PRIME OR CALCULATING THE FACTORIAL

import java.util.*;

class primeorfactorial

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter the number");

int n=sc.nextInt();

System.out.println("press 1 for checking if no. is prime or not\npress 2 for printing factorial of


it");

int choice=sc.nextInt();

switch(choice)

case 1:

int f=0;

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

if(n%i==0)

f++;

if(f==2)

System.out.println("a prime no.");

else

{
System.out.println("not a prime no.");

break;

case 2:

int fact = 1;

for (int i = n; i > 0; i--)//6,5,4,3,2,1

switch (i)

case 0:

case 1:

fact =fact* 1;

break;

default:

fact=fact* i;//7,42,210,840,2520,5040,5040

break;

System.out.println("Factorial of " + n + " is " + fact);

break;

}
//WAP TO ENTER THE GRADES AND GIVE MARKS ACCORDING TO THE SLAB

import java.util.*;

class program1hw

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int average=0;

System.out.println("enter the marks of subject 1");

int no1=sc.nextInt();

System.out.println("enter the marks of subject 2");

int no2=sc.nextInt();

System.out.println("enter the marks of subject 3");

int no3=sc.nextInt();

average=(no1+no2+no3)/3;

if(average>=90&&average<=100)

System.out.println("GRADE A");

else if(average>=80&&average<=89)

System.out.println("GRADE B");

else if(average>=70&&average<=79)

System.out.println("GRADE C");

else if(average>=60&&average<=69)

System.out.println("GRADE D");

else

System.out.println("GRADE F");

}
// WAP TO ENTER THE DISTANCE TRAVELLED AND CALCULATE THE TAXI BILL ACCORDINGLY

import java.util.*;

class taxibill

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter the distance travelled");

int d=sc.nextInt();

double bill=0.0;

if(d>0&&d<=5)

bill=100.0;

else if(d<=15)

bill=100+(d-5)*10;

else if(d<=25)

bill=200+(d-15)*8;

else if(d>25)

bill=280+(d-25)*5;

System.out.println("Taxi Fare: " +bill);

}
//wap to input and check if the no. is a spy no. or not
//wap to input a no. and check if it is a trimorphic no. or not

import java.util.*;

class trimorphic

public static void main(String args[])

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");//5

int n = scanner.nextInt();

int cube = n *n*n;//125

int count = 1;

for(int i=n;i>0;i/=10) //i=5

count=count*10;//10

if (cube % count == n)

System.out.println(n + " is an trimorphic number.");

} else {

System.out.println(n+ " is not an trimorphic number.");

}
import java.util.*;

class spynumber

public static void main(String args[])

Scanner sc=new Scanner(System.in);

System.out.println("enter a number");//1124

int n=sc.nextInt();//1124

int p=1;

int s=0;

int d=0;

for(int i=n;i!=0;i/=10)

d=i%10;//4,2,1,1

p*=d;//4,8,8,8

s+=d;//4,6,7,8

if(p==s)

System.out.println("spy");

else

System.out.println("not spy");

You might also like