ICSE BlueJ Logical Program

Logical Questions for Java or BlueJ

(Note: All programs codes are Tested in BlueJ
(The programs which are not solved try it out yourself, because one same pattern questions already solved)

Questions Based on Logic & Calculation:

1. Accept the value of A, B & C then calculate this formula.

        R  =  6.5 (A + B)2 - 7.3 (B + C)1/2

                    (A + C)1/2

class ques1
{
  public static void main(String args[])
  {
    int a = 2,b = 3,c = 4;
    double r;
    double x = 6.5*Math.pow((a+b),2);
    double y = 7.3*Math.sqrt(b+c);
    double z = Math.sqrt(a+c);
    r = (x-y)/z;
    System.out.println ("The answer is : "+r);
  }
}

2. WAP to calculate the Simple Interest.

class ques2
{
  public static void main(String args[])
  {
    int p = 5000;
    int r = 5;
    int t = 2;
    float si = (p*r*t)/100;
    System.out.println ("Simple intrest = "+si);
  }
}
3. Calculate the area and circumference of circle.
class ques3
{
  public static void main(String args[])
  {
    int r = 3;
    double a = 3.14*r*r;
    double c = 2*3.14*r;
    System.out.println ("Area of the Circle of radious "+r+" is : "+a);
    System.out.println ("Circumference : "+c);
  }
}
4. Calculate the area of a triangle.
class ques4
{
  public static void main(String args[])
  {
    int a = 2,b = 3,c = 4;
    double area;
    double s = (a+b+c)/2.0;
    area = Math.sqrt(s*(s-a)*(s-b)*(s-c))/(2*a*b);
    System.out.println ("Area of the Triangle");
    System.out.println ("of sides "+a+","+b+","+c);
    System.out.println ("is : "+area);
  }
}
5. Write a program with supporting documentation to enter any three real numbers and calculate X where:
        X  =  Product of integer portion
            Sum of decimal portion
class ques5
{
  public static void main(String args[])
  {
    double n1 = 12.85,n2 = 7.19,n3 = 3.65;
    int i1 = (int) n1;
    int i2 = (int) n2;
    int i3 = (int) n3;
    double d1 = n1-i1;
    double d2 = n2-i2;
    double d3 = n3-i3;
    double x = (i1*i2*i3)/(d1+d2+d3);
    System.out.println ("The value of X is : "+x);
  }
}

Questions Based on Condition:

6. WAP to check whether a number is divisible by 5 or not.
class ques6
{
  public static void main(String args[])
  {
    int n = 10;
    if(n%5 =  = 0)
      System.out.println ("The number "+n+" is divisible by 5");
    else
      System.out.println ("The number "+n+" is not divisible by 5");
  }
}
7. Accept a numbers and check whether the number is divisible by both 2 and 3 or not.
class ques7
{
  public static void main(String args[])
  {
    int n = 10;
    if(n%2 =  = 0 && n%3 =  = 0)
      System.out.println ("The number "+n+" is divisible by 2 and 3");
    else
      System.out.println ("The number "+n+" is not divisible by 2 and 3");
  }
}
8.  Write two separate programs to accept three numbers and find which one is greater (one using if statement and another using ternary operator).
class ques8
{
  public static void main(int a,int b,int c)
  {
    int max = (a>b) ? ((a>c)?a:c) : ((b>c)?b:c);
    System.out.print ("The Highest Number is : "+max);
  }
}
9.  Accept a numbers and find out the given number is divisible by 5 or not, if not then print the nearest number from the given number which is divisible by 5.
class ques9
{
  public static void main(int n)
  {
    int r = n%5;
    if(r =  = 0)
      System.out.println ("The number "+n+" is divisible by 5");
    else
      if(r>2)
        System.out.println ("The nearest number is "+(n-r+5));
      else
        System.out.println ("The nearest number is "+(n-r));
  }
}
10. Write a program to input the basic salary of a person. He get 15% of the basic as HRA, 15% of the basic as Conveyance allowance and 10% of the basic as Entertainment allowance. The total salary is calculated by adding Basic + HRA + Conveyance + Entertainment Allowance. Calculate and print the total salary of person.
class ques10
{
  public static void main(int basic)
  {
    double HRA = basic*.15;
    double conveyance = basic*.15;
    double entertainment = basic*.10;
    double totalSalary  =  basic + HRA + conveyance + entertainment;
    System.out.println ("Total Salary : "+totalSalary);
  }
}
11. A computer salesman gets commission on the following basis:
            Sales                        Commission Rate
            Rs. 0 - 20,000                      3%
            Rs. 20,000 - 50,000           12%
            Rs. 50,001 and more         31%
After accepting the sales as input, calculate and print his commission amount and rate of commission.
class ques11
{
  public static void main(int sales)
  {
    int rate  =  0;
    double commission  =  0.0;
    if(sales< = 20000)
    {
      rate = 3;
      commission = sales*.03;
    }
    if(sales> = 20001 && sales< = 50000)
    {
      rate = 12;
      commission = sales*.12;
    }
    if(sales> = 50001)
    {
      rate = 31;
      commission = sales*.31;
    }
    System.out.println ("Commission Rate : "+rate+"%");
    System.out.println ("Commission Amount : "+commission);
  }
}
12. Write a program to enter the three sides of a triangle. Decide whether it is a scalene, isosceles or equilateral triangle.
public class ques12
{
  public static void main(String args[])
  {
    int a  =  Integer.parseInt(args[0]);
    int b  =  Integer.parseInt(args[1]);
    int c  =  Integer.parseInt(args[2]);
    if (a =  = b && b =  = c && c =  = a)
      System.out.println ("Equileteral Triangle");
    else if (a! = b && b! = c && c! = a)
      System.out.println ("Scalean Triangle");
    else
      System.out.println ("Isoceles Triangle");
  }
}
13. A library charges fine for books returned late. Following are the fines: first five days 40 paisa per day, Six to ten days 65 paisa per day, above 10 days 80 paisa per day. Design a program to calculate the fine assuming that a book is returned N days late.
class ques13
{
  public static void main(int Ndays)
  {
    double fineAmount = 0;
    if(Ndays< = 5)
      fineAmount = Ndays*.40;
    if(Ndays> = 6 && Ndays< = 10)
      fineAmount = Ndays*.65;
    if(Ndays>10)
      fineAmount = Ndays*.80;
    System.out.println ("FINE AMOUNT (Rs.) : "+fineAmount);
  }
}
14. The telephone department wishes to compute monthly telephone bills for its customers using the following rules. Minimum Rs. 250 for first 80 message units, plus 60 paise per unit for next 60 units, plus 50 paise per unit for next 60 units, plus 40 paise per unit for any units above 200. Write a program that calculates the monthly bill, with input MESSAGE (the number of message units) and CUSTNO (the registration number of a customer). Then Display the bill in following format.
            CUSTOMER NO :
            MESSAGE UNITS :
            AMOUNT (Rs.) :
class ques14
{
  public static void main(int messageUnit,int customerNo)
  {
    double bill = 0;
    if(messageUnit< = 80)
      bill = 250;
    else if(messageUnit>80 && messageUnit< = 140)
      bill = 250+(messageUnit-80)*0.60;
    else if(messageUnit>140 && messageUnit< = 200)
      bill = 250+36+(messageUnit-140)*0.50;
    else if(messageUnit>200)
      bill = 250+36+30+(messageUnit-200)*0.40;
    System.out.println ("CUSTOMER NUMBER : "+customerNo);
    System.out.println ("MESSAGE UNIT : "+messageUnit);
    System.out.println ("BILL AMOUNT : "+bill);
  }
}
15. A security man paid at the hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid at 1.25 times of the hourly rate (R) for the next 16 hours and at 1.5 times of the hourly rate (R) for the further hours of work in the week. Taking the numbers of hours (H) and the rate per hour (R) as input, the weekly wages (W) is to be calculated.
class ques15
{
  public static void main(int H,int R)
  {
    double W = 0;
    if(H< = 40)
      W = H*R;
    else if(H>40 && H< = 56)
      W = 40*R+(H-40)*R*1.25;
    else if(H>56)
      W = 40*R+16*R*1.25+(H-56)*R*1.5;
    System.out.print ("The Weekly Wages : "+W);
  }
}
16. Write a program to compute BI-monthly telephone charges for subscriber. Use the following information:
        Fixed BI-monthly rent: Rs.380
        Free calls during two months: 120
        Charge/call beyond free limits upto 100 calls: Rs.1
        Charge per call in excess of 100 calls: Rs. 1.25
class ques16
{
  public static void main(int calls)
  {
    double bill = 280.0;
    if(calls>120 && calls< = 220)
      bill = bill+(calls-120)*1;
    else if(calls>220)
      bill = bill+100+(calls-220)*1.25;
    System.out.println ("BILL AMOUNT : "+bill);
  }
}
17. Write a program to input the code of a particular item, quantity purchased and rate. Then calculate the purchased price and print it along with gift to be presented. The gifts to the customers are given in the following manner:
        Amount of Purchase (Rs.)              Gift
        Between 100 to 500                 A key ring
        Between 500 to 1000                A leather purse
        Above 1000                         A pocket calculator
class ques17
{
  public static void main(int code, int qty, double rate)
  {
    double price = qty*rate;
    System.out.println ("Purchase Price : "+price);
    if(price> = 100 && price< = 500)
      System.out.println ("Gift item : Key Ring");
    if(price>500 && price< = 1000)
      System.out.println ("Gift item : Leather Purse");
    if(price>1000)
      System.out.println ("Gift item : Pocket Calculator");
  }
}

Some Questions on multiple IF condition

Q. Write a program to take the monthly salary from the user, find and display income tax with the help of the following slab:
   Monthly Salary                 Income Tax
   8000 or less                           Nil
   8000-9000                      20% of Monthly salary
   9000-10000                    30% of Monthly salary
   10000 or above              40% of Monthly salary
 
Q. A salesman earns a commission on the value of his sales as per the following table.
   Value of sales(Rs.)            Commission(%)
      1 - 999                               1
   1000 - 9999                          5
  10000 - 99999                      10
Write a program to calculate and print the commission using sale value as input. The program is to keep on calculating the commission for various salesmen until a sales value zero is input.
 
Q. A company wants to set target for each of the four regions (EAST, WEST , NORTH and SOUTH). The company allots the following percentage target for each region.
              East      15%
              West      25%
              North     30%
              South     30%
Write a program to pass through command line parameters, the total target amount proposed by the company and print out the breakup of the target for each region.
 
Q. Write a program to find the car bill for a particular tourist.
Type of car         Distance        Charge              Driver.
Maruti              < =  100          Rs.800              Rs.100.
                    >100 & < = 200    Rs.800+Rs10/km      Rs 300.
                                           above 100
                    >200            Rs.15per km         Rs 500
Sumo                < = 100           Rs.600              Rs 100.
                    >100 & < =  200   Rs.600+Rs.8/km      Rs 300
                                          above 100     
                    > 200           Rs.12 per km        Rs.500
 
Q. Write a program using method to calculate the salary increment of employees based on their basic pay. Calculate the final salary after increment.
             Basic Pay      Rise
             10700/-        550/-
             12500/-        750/-
             15000/-        1050/-
 
Q. Write a program using the this keyword, to calculate the prize amount for a cricketer depending upon his text average. Use the following date.
  Test Average             Graduate                 Prize Amount
    > = 80                    A                      Rs. 1,00,000.00
    80> & > = 65              B                      Rs. 50,000.00
    50> & > = 40              C                      Rs. 25,000.00
    <40                     D                      Rs. 10,000.00
 
Q. Using if-else statements write a program in java to calculate the grade as per the given criteria:
         Marks                 Grade
     > = 80 and <100          Excellent
     > = 70 and <80           First Div. 
     > = 60 and <70           Second Div.
     > = 50 and <60           Third Div.
     Less than 50           Fail
 
Q. Write a program to assign values the variable basic salary and calculate the DA and the gross salary and print them. The DA is calculated as per the rules given below:
    if basic< 2000             then DA is 5% of basic
    if basic> = 2000 & <7000     then DA is 8% of basic
    if basic> = 7000& <10000     then DA is 10% of basic
    if basic> = 10000            then DA is 12% of basic
    Gross Salary  =  Basic + DA.
 
Q. There are 55 employees in an organization. You have to display the number of employees getting Net-Salary above 20000 by taking only Basic_Salary as input and following the table given below.
  Basic Salary          DA (% Basic_salary)      IT (% Gross_Salary)
  Below 5000                     8%                     6%
  5000 to < 10000                15%                    9%
  10000and above                 18%                    12%
Where DA and IT are Dearness Allowance and income Tax respectively.
  Gross_Salary  =  Basic_Salary + DA
  Net_Salary  =  Gross_Salary - IT
 
Q. Calculate and display the traveling allowance for 50 employees of an organization by taking distance traveled as input. The organization gives traveling allowance according to the following table.
    Distance               Amount.
    < = 20                   Rs 200
    >20 and < = 50           Rs 200 + Rs 5 per extra km above 20
    >50 and < =  100         Rs 500 + Rs 5 per extra km above 50.
    >100                   Rs 15 per km.
 
Q. Commission according to the following tables:

            Sale (in Rs.)               Commission(% of sale)
                8000 or less                   Nil
                8000 - 9000                    12%
                9000 - 10000                   15%
                10000 or above                 18%
apart from this each salesman gets a fixed allowance of Rs 550 and also a bonus of Rs 500 if a salesman achieves the target of 10000. Display the total income of each salesman along with the sales. Also display the number of salesman having income of 5000 or above.

 
Q. A company has 120 employees who are divided into four grades as follows:
 Grade   Basic( Rs. per month)   D.A.(% of Basic)   H.R.A.(% of Basic)
   1        10,000 or more              40%                30%
   2        5,000 - 10,000              40%                25%
   3        < 5,000 but > 2,000         30%                20%
   4        2,000 or less               30%                15%
If the salary which is the total of Basic, D.A., and H.R.A., is above Rs.50,000 per month then Income Tax at the rate of 30% of the annual salary exceeding 50,000 is deducted on monthly basis at source. Taking name of the employees and the Basic(monthly) pay as inputs, a pay slip, which contains Name, Basic monthly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, for each employee is to be printed. Write a java program to perform this job.
 
Q. Define class calcComm with member variables: sales, commission
   method: 
    void acceptsales() to accept sales value
    float commAmt() to calculate and return commission amount.
the commission will be calculated according to the following criteria
    sales                                 commission rate
    above or equal to 5000                      15%
    above or equal to 3000 but below 5000       10%
    above or equal to 1000 but below 3000       5%
    below 1000                                  2%
 
Q. Define class calculateBill having member variable: calls, charge
   Member methods:
     void calCharge(int type) to calculate the telephone bill.
   Type is type of connection
     1. For domestic
     2. For business
   Bill will be calculated according to the following rule-
     Monthly rent - Rs. 450
     Number of call free - 100
     Next 150 calls - Rs. 1/call
     Next 100 calls - Rs. 1.50/call
     Extra calls - Rs. 2/call
for business type connection Rs 50/- will be paid extra by the customer
void display() to show the bill amount
    Write main program to accept no. of calls and display menu
      1. Domestic Connection
      2. Business Connection
    Enter Your Choice (1 or 2)
Bill will be calculated according to the option entered by the user and then finally display the bill.
 
Q. Write a program to calculate monthly telephone bill for a consumer after accept number of call according to given criteria.
    Monthly rent            Rs 400/-
    No. of free calls       100
    for next 150 calls      Rs. 1.25/call
    for extra calls         Rs. 1.50/call
 
Q. Write a program to input the sales or any 20 sales men. Calculate and print the commission with an added allowance of Rs. 500. The commission can be calculated by using the following table:-
    Sales              Commission
    Upto 5000             nil
    5001-8000             10%
    8001-10,000           12%
    10,001 Or more        15%
 
Q. Write a Java program to accept an amount from the user and hence
find in each case:-
a) No of Rs. 100 notes and the remainder amount.
b) No of Rs. 50 notes and the remainder amount.
c) No of Rs. 20 notes and the remainder amount.
d) No of Rs. 10 notes and the remainder amount.
Eg. In Rs. 542; No of Rs. 100  =  5, Remainder  =  Rs. 42
No of Rs. 50  =  10, Remainder  =  Rs. 42
No of Rs. 20  =  27, Remainder  =  Rs. 2.
No of Rs. 10  =  54, Remainder  =  Rs. 2.
 
Q. A class namely student has three data member Name, roll and Marks of 5 Subjects the steam is assigned based on the following criteria :
       Avg. Marks                 Stream
     90% and above          science with computers
     80% ___89%             science without Computers
     70%____79%             commerce with Maths
     60%___69%              commerce without Maths
Write a program to declare a class student and allot the stream and print them.
 
Q. ABC stand decided to take charge for the parking of 2wheeler, 3wheeler and 4wheller (same charges) as per the following criteria:
    No. of Hrs. Parked Charge
    upto 8 hrs Rs 10
    next 8 hrs Rs. 6 for additional 8 hours
    above 16 hours Rs. 5 for each addition 8 hrs.
Input number of hours parked and prints the charges as per given criteria.
 

Questions Based on Loops or Nested Loops

18. Display the first ten natural numbers (using for, while and do-while loop).
 
19. Display the first ten odd numbers and the sum of them.
 
20. Write a program to Display the table of given number.
 
21. The present population of a country is PO and it increases by 5% every year. The population (P) after n years is given by the formula: P  =  PO (1.05)n. Write a program to find the population every year for the next ten years.
 
22. Generate the following series
 (a) 1 2 4 7 11 16 22
class ques22a
{
  public static void main(String args[])
  {
    int s = 1;
    for(int i = 1;i< = 7;i++)
    {
      System.out.print (s+" ");
      s = s+i;
    }
  }
}
 (b) 0 1 3 6 10 15 21
class ques22b
{
  public static void main(String args[])
  {
    int s = 0;
    for(int i = 1;i< = 7;i++)
    {
      System.out.print (s+" ");
      s = s+i;
    }
  }
}
 (c) 0 3 8 15 24 35
class ques22c
{
  public static void main(String args[])
  {
    for(int i = 1;i< = 6;i++)
      System.out.print ((int) Math.pow(i,2)-1 + " ");
  }
}
 (d) 0 1 1 2 3 5 8 13 (fibonacci series)
class ques22d
{
  public static void main(String args[])
  {
    int a = 0,b = 1,c,i;
    for(i = 1;i< = 8;i++)
    {
      System.out.print (a+" ");
      c = a+b;
      a = b;
      b = c;
    }
  }
}
 (e) 1 2 2 4 8 32
class ques22e
{
  public static void main(String args[])
  {
    int a = 1,b = 2,c,i;
    for(i = 1;i< = 6;i++)
    {
      System.out.print (a+" ");
      c = a*b;
      a = b;
      b = c;
    }
  }
}
 (f) 2 3 4 6 6 9 8 12 10 15
class ques22f
{
  public static void main(String args[])
  {
    for(int i = 1;i< = 5;i++)
      System.out.print ((i*2)+" "+(i*3)+" ");
  }
}
 (g) 1 5 2 4 3 3 4 2 5 1
class ques22g
{
  public static void main(String args[])
  {
    int i;
    int a = 1,b = 5;
    for(i = 1;i< = 5;i++)
    {
      System.out.println (a+" ");
      System.out.println (b+" ");
      a++;
      b--;
    }
  }
}
 (h) 0 7 26 63 124
class ques22h
{
  public static void main(String args[])
  {
    int n;
    for(int i = 1;i< = 5;i++)
    {
      n = ((int) Math.pow(i,3)) - 1;
      System.out.print (n+" ");
    }
  }
}
23. Calculate the Sum of given series
 (a) S  =  1 + 2 - 3 + 4 - 5 + 6 - 7 + 8 - 9 + ……………… + Nth
 
 (b) S  =  (X+1)2+(X+2)3+(X+3)4+(X+4)5+…………… +(X+N)N+1
 
 (c) S  =  (1+2) + (1+2+3) + (1+2+3+4) + ………… + (1+…………+15)
 
 (d) S  =  1 + X + 2!X2 + 3!X3 + 4!X4
 
 (e) S  =  X2 + X3 + X4 + X5 + X6

         2!   3!  4!   5!   6!

 
 (f) S  =  1x2 + 2x3 + 3x4 + 4x5 + ... + 19x20
 

Typical Logical Questions:

24. WAP to display the factorial of the first ten natural numbers.
class ques24
{
  public static void main(String args[])
  {
    int f = 1;
    for(int i = 1;i< = 10;i++)
    {
      f = f*i;
      System.out.println ("The factorial of number "+i+" is "+f);
    }
  }
}
25. Write a program to print all the factors of a number.
class ques25
{
  public static void main(String args[])
  {
    int n  =  Integer.parseInt(args[0]);
    System.out.println ("The all Factors of given no. "+n+" is");
    for(int i = 1;i< = n;i++)
    {
      if(n%i =  = 0)
        System.out.println (i);
    }
  }
}
26. WAP to accept a number and check whether the number is perfect number or not. A number is called perfect number, if the sum of all factors (except number itself) of the number is equal to that number. (For e.g. 6 is a perfect number. Factors are 1, 2 & 3 and the sum is 1+2+3 = 6.)
class ques26
{
  public static void main(String args[])
  {
    int i,s = 0;
    int n  =  Integer.parseInt(args[0]);
    for(i = 1;i<n;i++)
    {
      if(n%i =  = 0)
        s = s+i;
    }
    if(n =  = s)
      System.out.println ("The given no. "+n+" is a Perfect no");
    else
      System.out.println ("The given no. "+n+" is not a Perfect no");
  }
}
27. WAP to generate all Perfect numbers up to 1000.
class ques27
{
  public static void main(String args[])
  {
    int i,s,n;
    System.out.println ("The Perfect nos between 1 to 1000 are ");
    for(n = 1;n< = 1000;n++)
    {
      s = 0;
      for(i = 1;i<n;i++)
      {
        if(n%i =  = 0)
          s = s+i;
      }
      if(n =  = s)
        System.out.println (n);
    }
  }
}
28. Write a program to accept a number, check whether the numbers is prime number or not. If number is prime, then display "PRIME NUMBER" or display "NOT A PRIME NUMBER".
class ques28
{
  public static void main(String args[])
  {
    int i,f = 0;
    int n  =  Integer.parseInt(args[0]);
    for(i = 2;i<n;i++)
    {
      if(n%i =  = 0)
      {
        f = 1;
        break;
      }
    }
    if(f =  = 0)
      System.out.print ("The given no. "+n+" is a prime number");
    else
      System.out.print ("The given no. "+n+" is not a prime number");
  }
}
29. Write a program to display all prime numbers between 100 to 200.
class ques29
{
  public static void main(String args[])
  {
    int i,f,n;
    System.out.print ("The Prime nos between 100 to 200 are : ");
    for(n = 100;n< = 200;n++)
    {
      f = 0;
      for(i = 2;i<n;i++)
      {
        if(n%i =  = 0)
        {
          f = 1;
          break;
        }
      }
      if(f =  = 0)
        System.out.print (n+" ");
    }
  }
}
30. The production (P) of crude oil of a country in millions of barrel may be estimated by the following set of equations, where t represent the times in years. P = 5+3t, for 0< = t< = 3 and P = 14+(T-5/2)^2, for t>3, Write a program to print the quantity of production for every year from t = 1 to 10.
 
31. Write a program to accept a number then print the sum of digits and number of digits present in it. (E.g. If the input number is 225, the sum of digits is 9 and number of digits is 3).
class ques31
{
  public static void main(int n)
  {
    int s = 0,c = 0,d;
    while(n>0)
    {
      d = n%10;
      s = s+d;
      c = c+1;
      n = n/10;
    }
    System.out.println ("Sum of digits : "+s);
    System.out.println ("no. of digits : "+c);
  }
}
32. Write a program to accept a number then print the number in reverse order. (E.g. If the input number is 245, the output will be 542)
class ques32
{
  public static void main(int number)
  {
    int reverseNumber = 0, digit;
    while(number>0)
    {
      digit = number%10;
      reverseNumber = reverseNumber*10+digit;
      number = number/10;
    }
    System.out.println ("Reverse Number is : " +reverseNumber);
  }
}
33. Write a program to check whether a number is palindrome number or not. (Palindrome means, If the reverse of the number is same of original number)
class ques33
{
  public static void main(int number)
  {
    int reverseNumber = 0, orgNumber = number, digit;
    while(number>0)
    {
      digit = number%10;
      reverseNumber = reverseNumber*10+digit;
      number = number/10;
    }
    if(orgNumber =  = reverseNumber)
      System.out.println ("Number is Palindrom");
    else
      System.out.println ("Number is not Palindrom");
  }
}
34. A number is called Armstrong number if the sum of cube of each digit of the number is equal to that number. Write a program to accept a number then check whether the given number is Armstrong number or not. (E.g. 153 is a Armstrong number because 153 =  13 + 53 +33).
class ques34
{
  public static void main(int number)
  {
    double sum = 0;
    int orgNumber = number, digit;
    while(number>0)
    {
      digit = number%10;
      sum = sum+Math.pow(digit,3);
      number = number/10;
    }
    if(orgNumber =  = sum)
      System.out.println ("Number is Armstrong");
    else
      System.out.println ("Number is not Armstrong");
  }
}
35. Write a program to display all three digits Armstrong number.
class ques35
{
  public static void main()
  {
    int sum;
    int n, digit;
    for(int number = 100;number< = 999;number++)
    {
      sum = 0;
      n = number;
      while(n>0)
      {
        digit = n%10;
        sum = sum+(digit*digit*digit);
        n = n/10;
      }
      if(number =  = sum)
        System.out.println ("Armstrong Number is "+number);
    }
  }
}
36. Write a program to check whether all digits of the given number are same type or not (i.e. all are odd, all even numbers or both present)
 
37. Write a program to accept a number and then add all digits until you found a single digit number. If that single digit number is 1, then that number is called lucky number. (e.g. if number is 2345 then sum of its digits becomes 14, further sum of this digits is 5, so the number is not a lucky number)
class ques37
{
  public static void main(int number)
  {
    int sum, digit;
    while(number>9)
    {
      sum = 0;
      while(number>0)
      {
        digit = number%10;
        sum = sum+digit;
        number = number/10;
      }
      number = sum;
    }
    if(number =  = 1)
      System.out.println ("Lucky Number");
    else
      System.out.println ("Not Lucky Number");
  }
}
38. Display the following Design Using Nested Loops:

 
   *
  ***
 *****
*******
 *****
  ***
   *
class ast1
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
        System.out.print ("*");
      System.out.println ();
    }
    for(i = 4;i> = 1;i--)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
        System.out.print ("*");
      System.out.println ();
    }
  }
}
    *
   *+*
  *+++*
 *+++++*
*+++++++*
 *+++++*
  *+++*
   *+*
    *
class ast2
{
  public static void main(String args[])
  {
    int i,j,p = 40;
    for(i = 1;i< = 5;i++,p--)
    {
      for(j = 1;j< = p;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
      {
        if(j =  = 1 || j =  = i*2-1)
          System.out.print ("*");
        else
          System.out.print ("+");
      }
      System.out.println ();
    }
    p = p+2;
    for(i = 4;i> = 1;i--,p++)
    {
      for(j = 1;j< = p;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
      {
        if(j =  = 1 || j =  = i*2-1)
          System.out.print ("*");
        else
          System.out.ࡰrint("+");
      }
      System.out.println ();
    }
  }
}
   *
  ***
 *****
*******
class ast3
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
        System.out.print ("*");
      System.out.println ("");
    }
  }
}
   *
  ***
 *****
*******
 *   *
  * *
   *
class ast4
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
        System.out.print ("*");
      System.out.println ("");
    }
    for(i = 4;i> = 1;i--)
    {
      for(j = 1;j< = 40-i;j++)
         System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
      {
        if(j =  = 1 || j =  = i*2-1)
          System.out.print ("*");
        else
          System.out.print (" ");
      }
      System.out.println ("");
    }
  }
}
   *
  * *
 *   *
*     *
 *   *
  * *
   *
class ast5
{
  public static void main(String args[])
  {
    int i,j,p = 40;
    for(i = 1;i< = 5;i++,p--)
    {
      for(j = 1;j< = p;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
      {
        if(j =  = 1 || j =  = i*2-1)
          System.out.print ("*");
        else
          System.out.print (" ");
      }
      System.out.println ();
    }
    p = p+2;
    for(i = 4;i> = 1;i--,p++)
    {
      for(j = 1;j< = p;j++)
        System.out.print (" ");
      for(j = 1;j< = i*2-1;j++)
      {
        if(j =  = 1 || j =  = i*2-1)
          System.out.print ("*");
        else
          System.out.print (" ");
      }
      System.out.println ();
    }
  }
}
W
WE
WEL
WELC
WELCO
WELCOM
WELCOME
class pro
{
  public static void main(String args[])
  {
    String x = "WELCOME";
    int i,j;
    int l = x.length();
    for(i = 0;i< = l;i++)
    {
      for(j = 0;j<i;j++)
        System.out.print (x.charAt(j));
      System.out.println ();
    }
  }
}
A
Am
Ami
Amit
Amita
Amitab
Amitabh
class amitabh
{
  public static void main(String args[])
  {
    String x = "Amitabh";
    int i,j;
    for(i = 0;i< = x.length();i++)
    {
      for(j = 0;j<i;j++)
        System.out.print (x.charAt(j));
      System.out.println ();
    }
  }
}
A
BB
CCC
DDDD
EEEEEE
class alpha1
{
  public static void main(String args[])
  {
    int i,j,a = 65;
    for(i = 1;i< = 5;i++,a++)
    {
      for(j = 1;j< = i;j++)
        System.out.print ((char)a);
      System.out.println ();
    }
  }
}
A
AB
ABC
ABCD
ABCDE
class alpha2
{
  public static void main(String args[])
  {
    int i,j,a;
    for(i = 1;i< = 5;i++)
    {
      a = 64;
      for(j = 1;j< = i;j++)
        System.out.print ((char)(a+j));
      System.out.println ();
    }
  }
}
1111
2222
3333
4444
class pyr1
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 4;i++)
    {
      for(j = 1;j< = 4;j++)
        System.out.print (i);
      System.out.println ();
    }
  }
}
0
12
345
6789
class pyr2
{
  public static void main(String args[])
  {
    int i,j,a = 0;
    for(i = 1;i< = 4;i++)
    {
      for(j = 1;j< = i;j++)
      {
        System.out.print (a);
        a++;
      }
      System.out.println ();
    }
  }
}
1
12
123
1234
12345
class pyr3
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = i;j++)
      {
        System.out.print (j);
      }
      System.out.println ();
    }
  }
}
1
21
321
4321
54321
class pyr4
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = i;j> = 1;j--)
      {
        System.out.print (j);
      }
      System.out.println ();
    }
  }
}
55555
4444
333
22
1
class pyr5
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 5;i> = 1;i--)
    {
      for(j = i;j> = 1;j--)
        System.out.print (i);
      System.out.println ();
    }
  }
}
1
22
333
4444
55555
class pyr6
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = i;j++)
        System.out.print (i);
      System.out.println ();
    }
  }
}
54321
5432
543
54
5
class pyr7
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 5;j> = i;j--)
        System.out.print (j);
      System.out.println ();
    }
  }
}
54321
4321
321
21
1
class pyr8
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 5;i> = 1;i--)
    {
      for(j = i;j> = 1;j--)
        System.out.print (j);
      System.out.println ();
    }
  }
}
12345
1234
123
12
1
class pyr9
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 5;i> = 1;i--)
    {
      for(j = 1;j< = i;j++)
        System.out.print (j);
      System.out.println ();
    }
  }
}
12345
2345
345
45
5
class pyr10
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = i;j< = 5;j++)
        System.out.print (j);
      System.out.println ();
    }
  }
}
5
45
345
2345
12345
class pyr11
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 5;i> = 1;i--)
    {
      for(j = i;j< = 5;j++)
      {
        System.out.print (j);
      }
      System.out.println ();
    }
  }
}
5
54
543
5432
54321
class pyr12
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 5;i> = 1;i--)
    {
      for(j = 5;j> = i;j--)
        System.out.print (j);
      System.out.println ();
    }
  }
}
    1
   212
  32123
 4321234
543212345
class pyr13
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 5-i;j++)
        System.out.print (" ");
      for(j = i;j> = 1;j--)
        System.out.print (j);
      for(j = 2;j< = i;j++)
        System.out.print (j);
      System.out.println ();
    }
  }
}
    1
   121
  12321
 1234321
123454321
class pyr14
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 5-i;j++)
        System.out.print (" ");
      for(j = 1;j< = i;j++)
        System.out.print (j);
      for(j = i-1;j> = 1;j--)
        System.out.print (j);
      System.out.println ();
    }
  }
}
        1
       232
      34543
     4567654
    567898765
   67890109876
  7890123210987
 890123454321098
90123456765432109
class pyr15
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 9;i++)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      for(j = i;j< = (i*2)-1;j++)
        System.out.print (j%10);
      for(j = (i-1)*2;j> = i;j--)
        System.out.print (j%10);
      System.out.println ();
    }
  }
}
    1
   010
  10101
 0101010
101010101
class pyr16
{
  public static void main(String args[])
  {
    int i,j,a;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 40-i;j++)
        System.out.print (" ");
      a = i;
      for(j = 1;j< = i*2-1;j++,a++)
        System.out.print (a%2);
      System.out.println ();
    }
  }
}
    1
   123
  12345
 1234567
123456789
class pyr17
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 5-i;j++)
        System.out.print (" ");
      for(j = 1;j< = (i*2-1);j++)
        System.out.print (j);
      System.out.println ();
    }
  }
}
    1
   222
  33333
 4444444
555555555
class pyr18
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 5;i++)
    {
      for(j = 1;j< = 5-i;j++)
        System.out.print (" ");
      for(j = 1;j< = (i*2-1);j++)
        System.out.print (i);
      System.out.println ();
    }
  }
}
   1      1
  222    222
 33333  33333
44444444444444
class pyr19
{
  public static void main(String args[])
  {
    int i,j;
    for(i = 1;i< = 4;i++)
    {
      for(j = 1;j< = 5-i;j++)
        System.out.print (" ");
      for(j = 1;j< = (i*2-1);j++)
        System.out.print (i);
      for(j = 1;j< = (4-i)*2;j++)
        System.out.print (" ");
      for(j = 1;j< = (i*2-1);j++)
        System.out.print (i);
      System.out.println ();
    }
  }

}