import java.util.
*;
class Prog1
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n,d,s=0,rev=0;
System.out.println("Enter Any Triple digit number ");
n=sc.nextInt();
if(n>=100 && n<=999)
{
while(n!=0)
{
d=n%10;
s=s+d;
rev=rev*10+d;
n=n/10;
}
System.out.println("Total of the digits : "+s);
System.out.println("Reverse of the number :"+rev);
}
}
}
import java.util.*;
class Prog2
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a,b,c,m,s=0;
System.out.println("Enter any three different numbers");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
m=(a>b)?(a>c?a:c):(b>c?b:c);
while(a>=10)
a=a/10;
while (b>=10)
b=b/10;
while (c>=10)
c=c/10;
s=a+b+c;
System.out.println("Greater number is "+m);
System.out.println("Sum of first digit of three numbers "+s);
}
}
import java.util.*;
class Prog3
{
static void main()
{
Scanner sc=new Scanner(System.in);
double feet, yard,inch;
System.out.println("Enter measurement in feet ");
feet=sc.nextDouble();
yard=feet/3.0;
inch=feet*12;
System.out.println(feet+" feet = "+yard +" yard");
System.out.println(feet+" feet = "+inch+ " inch");
}
}
import java.util.*;
class Prog4
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a,b,c,s=0;
System.out.println("Enter any three different numbers");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
s=(a)-(-b)-(-c);
System.out.println("Sum is= "+s);
}
}
import java.util.*;
class Prog5
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a,b,c;
int ch;
System.out.println("Enter any two numbers :");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("----------MENU ----------");
System.out.println("Press 1. For Addition ");
System.out.println("Press 2. For Substraction ");
System.out.println("Press 3. For Multiplication ");
System.out.println("Press 4. For Division ");
System.out.print("Enter your choice :");
ch=sc.nextInt();
switch(ch)
{
case 1: c=a+b;
System.out.println("Addition of two numbers is "+c);
break;
case 2: c=a-b;
System.out.println("Substraction of two numbers is "+c);
break;
case 3: c=a*b;
System.out.println("Multiplication of two numbers is "+c);
break;
case 4: c=a/b;
System.out.println("Division of the two number is: "+c);
break;
default: System.out.println("WRONG CHOICE INPUT");
}
}
}
import java.util.*;
class Prog6
{
static void main()
{
Scanner sc=new Scanner(System.in);
int k;
double fare=0;
System.out.println("Enter Kilometers travelled");
k=sc.nextInt();
if (k>0 && k<=5)
{
fare= 10*k;
}
else if (k>5 && k<=15)
{
fare= (5*10) + ((k-5)*8);
}
else if (k>15 && k<=25)
{
fare= (5*10) + (10*8) + ((k-15)*7);
}
else if (k>25)
{
fare= (5*10) + (10*8) + (10*7) + ((k-25)*5);
}
System.out.println("Bus Fare is "+ fare);
}
}
import java.util.*;
class Prog7
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n,d,rev=0,t;
System.out.println("Enter Any number ");
n=sc.nextInt();
t=n;
while(n!=0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
if(t==rev)
{
System.out.println(t+" is Palindrome Number");
}
else
{
System.out.println(t+" is not Palindrome Number");
}
}
}
import java.util.*;
class Prog8
{
static void main()
{
Scanner sc=new Scanner(System.in);
double ar=0,l,b,s,r;
int ch;
System.out.println("----------MENU ----------");
System.out.println("Press 1. To find area of a Square ");
System.out.println("Press 2. To find area of a Rectangle ");
System.out.println("Press 3. To find area of a Circle ");
System.out.print("Enter your choice :");
ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println("Enter the Side of the Square ");
s= sc.nextDouble();
ar= s*s;
System.out.println("Area of Square = "+ar);
break;
case 2: System.out.println("Enter the Length and Breadth of the Rectangle ");
l= sc.nextDouble();
b= sc.nextDouble();
ar= l*b;
System.out.println("Area of Rectangle = "+ar);
break;
case 3: System.out.println("Enter the Radius of the Circle ");
r= sc.nextDouble();
ar= 3.14159*(r*r);
System.out.println("Area of Circle = "+ar);
break;
default: System.out.println("WRONG CHOICE INPUT");
}
}
}
import java.util.*;
class Prog9
{
static void main()
{
Scanner sc=new Scanner(System.in);
double c,f;
System.out.println("Enter Temperature in Celsius ");
c=sc.nextDouble();
f=(1.8 * c) + 32;
System.out.println("Temperature in Fahrenheit is "+f);
}
}
import java.util.*;
class Prog10
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a,b,c;
System.out.println("Enter 3 sides of a Triangle ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a==b && b==c && c==a)
{
System.out.println("Triangle is Equilateral Triangle");
}
else if (a==b || b==c || c==a)
{
System.out.println("Triangle is Isosceles Triangle");
}
else if (a!=b && b!=c && c!=a)
{
System.out.println("Triangle is Scalene Triangle");
}
}
}
import java.util.*;
class Prog11
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n,i,even=0,odd=0;
System.out.println("Enter any 10 numbers");
for(i=1;i<=10;i++)
{
n=sc.nextInt();
if(n%2==0)
{
even=even+n;
}
else if (n%2!=0)
{
odd=odd+n;
}
}
System.out.println("Total of all Even numbers "+even);
System.out.println("Total of all Even numbers "+odd);
}
}
class Prog12
{
static void main()
{
int i,a=0,b=1,c;
System.out.print("First 10 Fibonacci Series are: "+a+" "+b);
for(i=1;i<=8;i++)
{
c=a+b;
System.out.print(" "+c);
a=b;
b=c;
}
}
}
import java.util.*;
class Prog13
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a,b,x,i,hcf=0,lcm=0,ch;
System.out.println("Enter Two Numbers ");
a=sc.nextInt();
b=sc.nextInt();
x=a>b?a:b;
for(i=x;i>=1;i--)
{
if(a%i==0 && b%i==0)
{
hcf=i;
break;
}
}
lcm=a*b/hcf;
System.out.println("Press 1. to get L.C.M.");
System.out.println("Press 2. to get H.C.F.");
System.out.println("Enter your choice: ");
ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println("L.C.M. is "+lcm);
break;
case 2: System.out.println("H.C.M. is "+hcf);
break;
default: System.out.println("Enter 1 or 2 only");
}
}
}
import java.util.*;
class Prog14
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n,d,c=0,t;
System.out.println("Enter any number ");
n=sc.nextInt();
t=n;
while(n>0)
{
d=n%10;
if(d==0)
{
c++;
}
n=n/10;
}
if(c>0)
{
System.out.println(t+" is Duck number");
}
else
{
System.out.println(t+" is not Duck number");
}
}
}
import java.util.*;
class Prog15
{
static void main()
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter any number ");
n=sc.nextInt();
if(n%10==7 || n%7==0)
{
System.out.println(n+" is Buzz number");
}
else
{
System.out.println(n+" is not Buzz number");
}
}
}
Question 16:
(a)
class Pattern1
{
static void main()
{
for (int i=1;i<=5;i++)
{
for (int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
(b)
class Pattern2
{
static void main()
{
for (int i=5;i>=1;i--)
{
for (int j=1;j<=i;j++)
{
System.out.print("*"+" ");
}
System.out.println(i);
}
}
}
(c)
class Pattern3
{
static void main()
{
for (int i=5;i>=1;i--)
{
for (int j=1;j<=i;j++)
{
System.out.print((j*j)+" ");
}
System.out.println();
}
}
}