Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Q1)

import java.util.*;

class Ascending

public static void main()

Scanner sc= new Scanner(System.in);

System.out.println("Enter three numbers");

int n1=sc.nextInt();

int n2=sc.nextInt();

int n3=sc.nextInt();

System.out.println("Ascendin\nDescending");

System.out.println("enter choice");

int ch=sc.nextInt();

int res,res1,res2,res3;

switch(ch)

case 1:

res=Math.max(n1,Math.max(n2,n3));

res1=Math.min(n1,Math.min(n2,n3));

res2=Math.max(n1,n2);

res3=Math.min(res2,n3);

System.out.println("Ascending order:"+res+","+res3+","+res1);

break;

case 2:

res=Math.max(n1,Math.max(n2,n3));

res1=Math.min(n1,Math.min(n2,n3));
res2=Math.max(n1,n2);

res3=Math.min(res2,n3);

System.out.println("Descending order:"+res1+","+res3+","+res);

break;

Q2)

import java.util.*;

class AgeDistance

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter age and distance");

int age=sc.nextInt();

int dist=sc.nextInt();

if(age<10)

if(dist<10)

System.out.println("Railway Fare is Rs 5");

else if(dist>10&&dist<50)

System.out.println("Railway Fare is Rs 20");

else

System.out.println("Railway Fare is Rs 50");

else if(age>10&&age<60)
{

if(dist<10)

System.out.println("Railway Fare is Rs 10");

else if(dist>10&&dist<50)

System.out.println("Railway Fare is Rs 40");

else

System.out.println("Railway Fare is Rs 80");

else

if(dist<10)

System.out.println("Railway Fare is Rs 4");

else if(dist>10&&dist<50)

System.out.println("Railway Fare is Rs 15");

else

System.out.println("Railway Fare is Rs 35");

Q3)

import java.util.*;

class digit

public static void main()

char ch;
Scanner s=new Scanner(System.in);

System.out.println("Input a character: ");

ch = s.next().charAt(0);

if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))

System.out.println("This is an alphabet.");

if(ch>=65 && ch<=90)

System.out.println("This is Upper Case alphabet.");

else if(ch>=97 && ch<=122)

System.out.println("This is lower Case alphabet.");

else if(ch>='0' && ch<='9')

System.out.println("This is a digit.");

else

System.out.println("This is a special character.");

Q4)

import java.util.*;

class Lcm

{
public static void main()

Scanner sc= new Scanner(System.in);

System.out.println("Enter two numbers");

int x=sc.nextInt();

int y=sc.nextInt();

int r=0,a,b;

a=(x>y)?x:y;

b=(x<y)?x:y;

r=b;

while(a%b!=0)

r=a%b;

a=b;

b=r;

// int LCM=(x*y)/r;

System.out.println("GCD of two numbers"+r);

// System.out.println("LCM of two numbers"+LCM);

Q5)

import java.util.Scanner;

public class abundant

public static void main() {


Scanner in = new Scanner(System.in);

System.out.print("Enter the number: ");

int n = in.nextInt();

int sum = 0;

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

if (n % i == 0)

sum += i;

if (sum > n)

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

else

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

Q6)

import java.util.*;

class pattern

public static void main()

Scanner sc= new Scanner(System.in);

System.out.println("Series\nPattern");

System.out.println("enter choice");

int ch=sc.nextInt();
switch(ch)

case 1:

System.out.println("Enter nth term");

int n=sc.nextInt();

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

System.out.print(((i*i)-1)+",");

break;

case 2:

for(int i=5;i>=1;i--)

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

if(j%2==0)

System.out.print("0");

else

System.out.print("1");

System.out.println();

break;

}
}

Q7)

import java.util.*;

class equation

double equation(int x)

double p=2.4*Math.pow(x,2)+5.3*x+-1.6;

return p;

void input()

Scanner sc=new Scanner(System.in);

System.out.println("Enter value");

int a=sc.nextInt();

double k=equation(a);

System.out.println("Answer is="+k);

Q8)

import java.util.*;

class honda

Scanner sc=new Scanner(System.in);

byte type;

int cost;
void getType()

System.out.println("Enter type and previous cost");

type=sc.nextByte();

cost=sc.nextInt();

void find()

if(type==2)

cost=cost*10/100;

if(type==4)

cost=cost*12/100;

void printcost()

System.out.println("Type of engine:"+type);

System.out.println("New Cost of vehicle:"+cost);

public static void main()

honda h=new honda();

h.getType();

h.find();

h.printcost();

You might also like