Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Chapter - 6

Programs of Exercise 5
Q1)
WAP to input 6 numbers and display the largest number.
import java.util.*;
public class largest
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a,b,c,d,e,f,max;
System.out.println("Enter 6 numbers");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
d=sc.nextInt();
e=sc.nextInt();
f=sc.nextInt();
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
if(d>max)
max=d;
if(e>max)
max=e;
if(f>max)
max=f;
System.out.println("Largest number="+max);
}
}

Q2)
WAP to input 5 numbers and display the smallest number.
import java.util.*;
public class Smallest
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a,b,c,d,e,min;
System.out.println("Enter 5 numbers");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
d=sc.nextInt();
e=sc.nextInt();
min=a;
if(b<min)
min=b;
if(c<min)
min=c;
if(d<min)
min=d;
if(e<min)
min=e;
System.out.println("Smallest number="+min);
}
}

Q3)
WAP to input the length of three lines and check whether they can form a triangle or not. If they
can form a triangle check whether the triangle is Equilateral triangle, Isosceles triangle or Scalene
triangle.
import java.util.*;
public class Trinagle1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a,b,c;
System.out.println("Enter the length of three lines");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a+b>c && a+c>b && b+c>a)
{
System.out.println("They can form a triangle");
if(a==b && a==c && b==c)
System.out.println("Equilateral triangle");
else if(a==b || a==c || b==c)
System.out.println("Isosceles triangle");
else
System.out.println("Scalene triangle");
}
else
System.out.println("They cannot form a triangle");
}
}

Q4)
WAP to input the size of three angles and check whether they can form a triangle or not. If they
can form a triangle check whether the triangle is Acute Angled triangle, Right Angled triangle or
Obtuse Angled triangle.
import java.util.*;
public class Trinagle2
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a,b,c;
System.out.println("Enter the size of three angles");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a+b+c==180)
{
System.out.println("They can form a triangle");
if(a<90 && b<90 && c<90)
System.out.println("Acute Angled triangle");
else if(a==90 || b==90 || c==90)
System.out.println("Right Angled Traingle");
else
System.out.println("Obtuse Angled Triangle");
}
else
System.out.println("They cannot form a triangle");
}
}

You might also like