Java Control Statement Lab

If-Else

0. Find the given number is even or odd.


If-else-if-else

1. Write a program to calculate gross salary.
        DA=70% and HRA=10% if basic salary<15000.
        DA=98% and HRA=500 if basic salary>=15000.
NO DA HRA   if salary <10000

2. Write a program that inputs a pair of number num1 and num2 and divide the larger of the two by smaller. 
Note: it will first be necessary to test for a zero value, since divide by zero will cause program to halt immediately.

3. The marks obtained by student in five different subjects are input through the keyboard.the student get division or grade as per the following rule:
    -60% or above   ----    first class
    -50% to  59%  ------     second class
    -40% to  49%  ------     third class
    -Less than 40%   ------     Fail

Write a program to calculate the grades obtained by the student.

4. Solve above problem using Logical operator


5. Write a program to find all the types of roots of a  given quadratic  equation.

SWITCH

6. A bank offers 14%,15% and 16% interest on 1 year , 2 year and 3 year deposit. 
Write a programme  to enter rate, deposit amount. compute and print maturity amount.




WHILE

7.Write a program to find length of given number.

8.Write a program to convert decimal to binary.

9.Write a program to count the number of occurrence of digit in a number.

10.Write a program to find the sum of digit of a given number.

11. Write a program to reverse a given number.

12. Check the number is palindrome or not.

13. Write a program using while loop to calculate and print the first ‘N’ Ex=10 Fibonacci number starts with       (1,1),2, 3,5,8,13,21,34,55

14. Write a Program to calculate factorial of a given number.

15. Write a program to find a given number is prime or not .


16. Write a program to generate all 3 digit Armstrong numbers.

17. Write a program to sum the series
1!+2!+3!+---------+N!.


18. Write a program to find the sum of N numbers.

19. Generate  a fibonnaci series upto N and count the numbers.

20. Write  a program to generate fibonncci series upto given limit and count the number of prime number in the series and find the sum of prime number in the series.

Do While

21. Menu driven program

  1.   Reverse number.
  2. Sum of all digit.
  3. Number of digit.
  4. Product of all digit.
  5. Big digit.
  6. Smallest digit.



For loop

23. Write a program which accept a number ‘N’ and then find the sum of the integer from 1 to 2, then 1 to 3 then 1 to 4 and so forth until it display the sum of integers from 1 to N.

24. write a program to print a factorial table using for loop
For ex         1!    1
      2!               2
      3!               6

25. write a program to test whether a given number is prime or not.?(Use GOTO statement).

26. Above program without goto statement.

27. Print all the prime numbers between two given numbers.

28. Write a program to compute the sum of first ‘N’ terms (n>=1) of the series
          1-3+5-7+9……………………



For loop Nesting

29.Write a program to print the multiplication table
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
.
.
N
Reactions:

1 comment:

  1. import java.util.Scanner;
    class S21
    {
    public static void main(String ar[]){
    int ch,num,rem;
    Scanner obj=new Scanner(System.in);
    System.out.println("enter the value of num");
    num=obj.nextInt();
    System.out.println("enter the value of ch");
    ch=obj.nextInt();
    switch(ch)
    {
    case 1: int rev=0;
    while(num>0)
    {
    rem=num%10;
    rev=rev*10+rem;
    num=num/10;}
    System.out.println("reverse of number is"+rev);
    break;

    case 2: int sum=0;
    while(num>0){
    rem=num%10;
    sum=sum+rem;}
    System.out.println("sum of all digit"+sum);
    break;
    case 3: int digit=0;
    while(num>0)
    {
    digit++;
    num=num/10;}
    System.out.println("digit is in number is"+digit);
    break;
    case 4: int product=1;
    while(num>0)
    {rem=num%10;
    product=product*rem;
    num=num/10;
    }
    System.out.println("product of digit number"+product);
    break;
    case 5: int bigdigit=0;
    while(num>0)
    {
    rem=num%10;
    if(rem>bigdigit)
    { bigdigit=rem;}
    num=num/10;}
    System.out.println("bigdigit in a number"+bigdigit);
    break;
    case 6:int smallest=9;
    while(num>0)
    {rem=num%10;
    if(rem<smallest)
    {smallest=rem;
    }
    num=num/10;}
    System.out.println("smallest digit in this number is"+smallest);
    break;

    default :System.out.println("invalid case");
    break;
    }
    }
    }

    ReplyDelete