Sunday 29 March 2015

PROGRAM 18 : ENTER A STRING AND REMOVE THE DUPLICATE CHARACTERS OF STRING.

Example :


PROGRAM :

import java.io.*;
class RemoveDupChar
{
      public static void main(String args[])throws IOException
     {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter any word : ");
        String s = br.readLine();
        int l = s.length();
        char ch;
        String ans="";
        for(int i=0; i<l; i++)
       {
            ch = s.charAt(i);
            if(ch!=' ')
                ans = ans + ch;
            s = s.replace(ch,' '); //Replacing all occurrence of the current character by a space
               }
        System.out.println("Word after removing duplicate characters : " + ans);
     }
}

 
PROGRAM 17 : ENTER A STRING AND REMOVE REPEATED CHARACTERS FROM STRING.

Example:


PROGRAM :

import java.util.Scanner;
class RemoveRepChar
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a word:");
        String s = sc.nextLine();
         s = s + " "; // Adding a space at the end of the word
         int l=s.length(); // Finding the length of the word
         String ans=""; // Variable to store the final result
         char ch1,ch2;
        for(int i=0; i<l-1; i++)
        {
            ch1=s.charAt(i);
            ch2=s.charAt(i+1);
            if(ch1!=ch2) // Check that consecutive characters are not equal
                ans = ans + ch1;
        }
        System.out.println("Word after removing repeated characters = "+ans); // Printing the result
    }
}

Saturday 28 March 2015

PROGRAM 16 : ENTER A STRING AND ARRANGE THE CHARACTERS IN ALPHABETICAL ORDER,REMOVING ALL SPACES OF THE STRING.

Example:


 
 
PROGRAM :
 
 
import java.util.Scanner;
public class alphabeticalorder
{
   public static void main(String args[])
   {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter a string:");
       String str = sc.nextLine();
       str = str.toUpperCase();
       int l = str.length();
       int i , j;
       char arr[] = new char[l]; // creating 'char' array to store the characters of string
       for(i = 0 ; i<l ; i++)
           arr[i] = str.charAt(i);// METHOD IS USED TO EXTRACT THE CHARACTERS OF STRING
       char t; // TEMPORARY VARIABLE CREATED
       for(i = 0 ; i<l ; i++) // SORTING OF CHARACTERS IN ASCENDING ORDER BY USING BUBBLE SORTING TECHNIQUE
       {
           for(j = 0 ; j<l-i-1 ; j++)
           {
               if(arr[j]>arr[j+1]) // COMPARING THE ELEMENTS OF ARRAY
               {
                   t = arr[j]; // SWAPPING MECHANISM
                   arr[j] = arr[j+1];
                   arr[j+1] = t;
                }
            }
        }
       String s = ""; //CREATE A NEW STRING TO REMOVE THE SPACES
       for(i = 0 ; i<l ; i++)
          s+=arr[i];
       s = s.trim(); // USING trim() method for eliminating the extra spaces
       System.out.println("OUTPUT:");
       System.out.println(s);
    }
}

PROGRAM 15 : ENTER THE NUMBER OF TERMS OF PELL SERIES TO BE PRINTED

(Pell series is series of numbers which starts with 1 and then 2 and goes on.
 The next term is sum of double of precedent number and the number before the precedent number.)

Example :


'5' is the sum of double of '2' and '1' , i.e. , (1 + (2x2)). This way the series goes on.


PROGRAM :

import java.util.Scanner;
public class pellseries
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of terms in pell series:");
        int n = sc.nextInt();
        int a = 1 , b = 2 , t = 3 , c;
        System.out.print(a + " " + b); // FIRST TWO TERMS ARE PRINTED
        while(t<=n)
        {
            c = a + (2*b.);  //THIRD TERM IS SUM OF THE TWICE VALUE OF THE PRECEDENT VALUE OF THAT OF THE VALUE PRECEDING THE PREVIOUS VALUE ALSO
            a = b; // SWAPPING VALUES
            b = c;
            System.out.print(" " + c);
            t++; // INCREASING THE NUMBER OF TERMS BY ONE
            }
        }
    }

 

PROGRAM 14 : TO CHECK WHETHER THE NUMBER ENTERED IS PART OF THE FIBONACCI SERIES.

(Fibonacci series starts with '0' and '1' and the next term is the sum of the previous two terms of series. It goes like this : 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21...................)

Example:


PROGRAM :

import java.util.Scanner;
public class isFibonacci
{
   public static void main(String args[])
   {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter a number:");
       int n = sc.nextInt();
       if(n<0) // THE NUMBER ENTERED SHOULD BE EQUAL TO OR GREATER THAN ZERO
       {
           System.out.println("negative number entered.");
        }
        else
        {
            int a = 0 , b = 1 , c = 0;
            while(c<n){ // THE SERIES GOES ON TILL IT REACHES THE SEARCH ELEMENT OR EXCEEDS IT.
                c = a + b; // THIRD TERM IS EQUAL TO SUM OF PRECEEDING TWO VALUES
                a = b; // SWAPPING POSITIONS OF VALUE
                b = c;
            }
       if(c==n)
           System.out.println("Output : The number belongs to Fibonacci Series.");
       else
           System.out.println("Output : The number does not belong to Fibonacci Series.");
     }
   }
}

Friday 27 March 2015

PROGRAM 13 : TO ACCEPT TWO DIFFERENT STRINGS AND SWAP THE VALUES WITHOUT USING THE CALL BY VALUE OR CALL BY REFERENCE MECHANISM.

(Swapping values means to interchange values of two different variables with each other.)

Example:


PROGRAM :

import java.util.Scanner;
public class swappingstrings
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the first string S1:");
        String s1 = sc.nextLine();
        s1 = s1.trim(); // REMOVES ALL EXTRA SPACES BEFORE AND AFTER THE STRING
        int len = s1.length();
        System.out.println("Enter the second string S2:");
        String s2 = sc.nextLine();
        s2 = s2.trim();
        System.out.println("------------------------------------------------");
        System.out.println("Value of s1 before swapping: " + s1);
        System.out.println("Value of s2 before swapping: " + s2);
        System.out.println("------------------------------------------------");
        s1 = s1 + s2; // WE ARE JOINING BOTH THE STRINGS
        s2 = s1.substring(0 , len); // USING STRING METHOD TO EXTRACT A PARTICULAR PART OF STRING
        s1 = s1.substring(len); // TO EXTRACT THE REMAINING PART.
        System.out.println("------------------------------------------------");
        System.out.println("Value of s1 after swapping: " + s1);
        System.out.println("Value of s2 after swapping: " + s2);
        System.out.println("------------------------------------------------");
    }
}
PROGRAM 12 : ENTER THE LOWER LIMIT AND UPPER LIMIT TO GET PAIRS OF TWIN PRIME NUMBERS.

Example:


 
 
PROGRAM:
 
 
import java.util.Scanner;
public class twinprime
{
    public static boolean isprime(int n) // CHECKS THAT THE NUMBER IS PRIME OR NOT
    {   int count = 0;
        for(int i = 1 ; i<=n ; i++)
        {  
            if(n%i==0)
               count++;
            }
        if(count==2)
          return true;
        else
          return false;
        }
       
    public static void main(String args[])
    {
        twinprime obj = new twinprime();
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter lower range:");
        int a = sc.nextInt();
        System.out.println("Enter upper range:");
        int b = sc.nextInt();
        if(a>b || a==b) // THE LOWER LIMIT CANNOT BE GREATER THAN UPPER LIMIT
           System.out.println("INVALID RANGE ENTERED.");
        else
        {
            System.out.println("The pairs of twin prime numbers in the following range are:");
            for(int i = a ; i<=b-2 ; i++)
            {
                if(obj.isprime(i)==true && obj.isprime(i+2)==true) // CONSECUTIVE NUMBERS CAN BE PRIME
                     System.out.println("(" + " " + i + " , " + (i+2) + " )");
                    }
                }
            }
        }
PROGRAM 11 : TO FIND THE DIGIT FREQUENCY , THAT IS THE NUMBER OF TIMES A DIGIT HAS APPEARED IN THE NUMBER.

EXAMPLE :



PROGRAM :

import java.io.*;
class Digit_Freq
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter any number : ");
        String num = br.readLine();
        System.out.println("Output:");
        System.out.println("====================");
        System.out.println("Digit\tFrequency");
        System.out.println("====================");
       
        System.out.println();
        int count = 0;
        char ch;
        for(int i = 48 ; i<=57 ; i++) // THE ASCII VALUES OF '0' TO '9'(48 TO 57)
        {   ch = (char)i; // CONVERTS THE ASCII VALUE TO CHARACTER
            for(int j = 0 ; j<num.length() ; j++)
            {
                if(num.charAt(j)==ch) // CHECKS OCCURRENCES OF THE DIGIT IN THE WHOLE NUMBER
                    count++; // INCREASES COUNT BY '1'
            }
            if(count>0){ // DISPLAYS ONLY THE DIGITS THAT ARE IN THE NUMBER
               System.out.print(ch+ "        " + count);
               System.out.println();
            } 
               count = 0; // COUNT IS MADE ZERO SO THAT IT CHECKS THE OCCURRENCES OF NEXT DIGIT
            }
        }
    }
PROGRAM 10 : ENTER AN AMOUNT TO FIND THE DENOMINATIONS OF AMOUNT

Example:


PROGRAM:

import java.util.Scanner;
public class denominationofamount
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter an amount to find out it's denominations:");
        int num = sc.nextInt() ;
        int copy = num;
        int deni[] = {1000 , 500 ,100 , 50 , 20 , 10 , 5 , 2 , 1}; // ARRAY STORES THE DENOMINATION VALUES
        int totalnumberofnotes = 0; // STORES THE NUMBER OF NOTES
        int count;
        System.out.println("\nDENOMINATIONS:\n");
        for(int i = 0 ; i<9 ; i++)
        {
           count = num/deni[i]; // DIVIDES NUMBER ACCORDING TO ELEMENT NUMBER IN ARRAY
           if(count!=0) // CHECKS THAT THE DIGIT IS NOT A ZERO
              System.out.println(deni[i] + "\tX\t" + count + "\t=\t" + (deni[i]*count));
           totalnumberofnotes+=count;
           num = num%deni[i]; // LEAVES A REMAINDER WHICH IS USED FURTHER
        }
        System.out.println("-----------------------------------------------------------------");
        System.out.println("TOTAL AMOUNT =                  " + copy);
        System.out.println("-----------------------------------------------------------------");
        System.out.println("TOTAL NUMBER OF NOTES = " + totalnumberofnotes);
    }
}
PROGRAM 9 : TO CONVERT A NUMBER ( NOT MORE THAN 3999) INTO A ROMAN NUMERAL

Example:


PROGRAM:

import java.util.Scanner;
public class decimaltoroman
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number to find out its ROMAN NUMERAL:(not more than 3999)");
        int num = sc.nextInt();
        String thou[]={"","M","MM","MMM"};
        String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
        String ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
        String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
        if(num>3999)
          System.out.println("Sorry. number entered out of bound.");
        else
        {
          int th = num/1000; // DIVIDES NUMBER BY 1000 TO FIND THE THOUSANDTH DIGIT
          int h = (num/100)%10; // TO FIND THE HUNDRETH DIGIT
          int t = (num/10)%10; // TO FIND THE TENTH DIGIT
          int u = num%10; // TO FIND THE SINGLE LAST DIGIT
          System.out.println("ROMAN NUMERAL: " + thou[th] + hund[h] + ten[t] + unit[u]); // WILL REFER TO THE ARRAYS ABOVE TO GET THE ROMAN NUMBER
        }
    }
}
 

Thursday 26 March 2015

PROGRAM 8 : ENTER A NUMBER TO CHECK WHETHER IT IS A DISARIUM NUMBER OR NOT.

( Disarium number is a number which is equal to the total sum of its digits raised to their position in the number.)

Example : 135 is a DISARIUM NUMBER .

SUM = 1^1 + 3^2 + 5^3(position of '1' is first ; of '3' is second and '5' is third)
         = 1 + 9 + 125   ( '^' is to express the number "raised to" some other number)
         = 135 , i.e the number itself 


PROGRAM:

import java.io.*;
public class disarium_number
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a number to find out whether it is a disarium number or not:");
        int num = Integer.parseInt(br.readLine());
        int copy = num , d , sum = 0;
        String str = Integer.toString(num); // CONVERTING INTEGER TO STRING
        int len = str.length(); // FINDING LENGTH OF THE STRING
        while(len>0){
            d = copy%10; // EXTRACTING LAST DIGIT OF THE NUMBER
            sum += (int)Math.pow(d , len); // ADDING THE NUMBER RAISED TO ITS EXPONENT THAT IS THE 'len'
            len--; // reducing len by '1'
            copy = copy/10; // dividing the number by '10'
        }
        if(sum==num) // checking whether total sum of the raised numbers is equal to the number itself
           System.out.println("The number is a disarium number.");
        else
           System.out.println("The number is not a disarium number.");
        }
    }
PROGRAM 7 : ENTER A STRING AND REPLACE ALL OCCURENCES OF VOWELS WITH THE ALPHABET FOLLOWING IT , INTO THE STRING.

Example:
 
 
PROGRAM:
 
 
import java.util.Scanner;
public class replacingvowels2
{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a string to replace its vowels:");
        String str = sc.nextLine();
        str = str.trim(); // WILL REMOVE ALL EXTRA SPACES BEFORE AND AFTER THE STRING
        str = str.toUpperCase(); // WILL CHANGE ALL CHARACTERS TO UPPERCASE
        int a = str.length();
        char ch;
        int b;
        for(int i = 0 ; i <a ; i++){
            ch = str.charAt(i);  // EACH CHARACTER WILL BE CHECKED WHETHER IT IS A VOWEL OR NOT.
            b = (int)ch; // WILL FIND THE ASCII VALUE OF CHARACTER
            switch(ch) // A TYPE OF DECISION MAKING STATEMENT THAT CHECKS CHARACTER WITH EVERY CASE
            {
                case 'A':
                case 'E':
                case 'I':
                case 'O':
                case 'U':
                b = b+1; // WILL INCREASE THE ASCII VALUE BY 1
                str = str.replace(ch , (char)b); // WILL REPLACE ALL OCCURENCES OF THE VOWEL WITH NEXT ALPHABET IN ORDER
                break;
                default:
            }
        }
        System.out.println("CHANGED STRING:");
        System.out.println(str); // WILL OUTPUT THE CHANGED STRING
    }
}
 

PATTERN PROGRAM 2 : ENTER NUMBER OF TERMS FROM 1 TO 5 (NOT MORE)AND YOU WILL GET A PATTERN OF ALPHABET 'a'.

Example: you have entered the number '4' ; then output is:
 
 
PROGRAM:
 
import java.util.Scanner;
public class assign11
{
   public static void main(String args[]){
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the number of terms to be printed in the series(FROM 1 TO 5):");
       int n = sc.nextInt();
       if(n<1||n>5)
       System.out.println("Wrong input.");
       else{
       int h = 0;
       int d = n-1;
        for(int i = 1 ; i<=n ; i++){
           for(int s = 1 ; s<= d ; s++){
               System.out.print(" ");
            }
            System.out.print("a");
           for(int t = 1 ; t<= h ; t++){
                if(t%2==0){
                    System.out.print("a");
                }
                else{
                    System.out.print(" ");
                }
           }
           h = h + 2;
           d = d - 1;
           System.out.println();
        }
        if(n%2==0){
          int c = n+2;
          for(int k = 1 ; k<= n ; k++){
            for(int s = 1 ; s<=k-1 ; s++){
                System.out.print(" ");
            }
            System.out.print("a");
            for(int j = 1 ; j<=c ; j++){
                if(j%2==0){
                    System.out.print("a");
                }
                else{
                    System.out.print(" ");
                }
            }
            c = c - 2;
            System.out.println();
          }
        }
        else{
            int c = n +3;
            for(int k = 1 ; k<= n ; k++){
            for(int s = 1 ; s<=k-1 ; s++){
                System.out.print(" ");
            }
            System.out.print("a");
            for(int j = 1 ; j<=c ; j++){
                if(j%2==0){
                    System.out.print("a");
                }
                else{
                    System.out.print(" ");
                }
            }
            c = c - 2;
            System.out.println();
          }
        }
    }
}
}
PATTERN PROGRAM 1 : ENTER THE NUMBER OF TERMS SO THAT A PATTERN OF NUMBERS IS PRODUCED.

Example : you have entered the number '5' ; then the following output comes:



PROGRAM :

import java.util.Scanner;
public class assi
{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of terms to be printed:");
        int n = sc.nextInt();
        int c = n - 1;
        int f = 1;
        for(int i = 1 ; i<=n ; i++){
            for(int s = 1 ; s<=c ; s++){
                System.out.print(" ");
            }
            c = c - 1;
            for(int j = 1 ; j<=f ; j++){
                System.out.print(j);
            }
            f = f + 2;
            System.out.println();
        }
        int d = 1;
       
        for(int i = 1 ; i<= n ; i++){
            for(int s = 1 ; s<=d ; s++){
                System.out.print(" ");
            }
            for(int a = 1 ; a<=f - 4 ; a++){
                System.out.print(a);
            }
            f = f - 2;
            d = d + 1;
            System.out.println();
        }
    }
}
PROGRAM 6 : TO FIND COMPOUNDED AMOUNT BY ENTERING CHOICE '1' OR TO FIND RECURRING DEPOSIT FINAL AMOUNT BY ENTERING CHOICE '2'
YOU ARE ASKED TO ENTER THE PRINCIPAL , RATE OF INTEREST AND TIME IN YEARS.

(FOR COMPOUND INTEREST , FORMULA : AMOUNT=PRINCIPAL*(1+RATE/100)^TIME

FOR RECURRING DEPOSIT,FORMULA : AMOUNT = (p * t * 12) + p*((t*12)*((t*12)+1)/2)*(r/100)*(1/12)))

PROGRAM:

import java.util.Scanner;
public class bankdeposit
{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter your choice : 1 for term deposit and 2 for recurring deposit");
        int ch = sc.nextInt();
        double p , r , t , am;
        switch(ch){
            case 1: System.out.println("Enter Principal amount:");
                    p = sc.nextDouble();
                    System.out.println("Enter Rate of interest:");
                    r = sc.nextDouble();
                    System.out.println("Enter Time period in years:");
                    t = sc.nextDouble();
                    am = p * Math.pow(1 + (r/100) , t);
                    System.out.println("The amount is : " + am);
                    break;
            case 2: System.out.println("Enter Principal amount:");
                    p = sc.nextDouble();
                    System.out.println("Enter Rate of interest:");
                    r = sc.nextDouble();
                    System.out.println("Enter Time period in years:");
                    t = sc.nextDouble();
                    am = (p * t * 12) + p*((t*12)*((t*12)+1)/2)*(r/100)*(1/12);
                    System.out.println("The amount is : " + am);
                    break;
            default: System.out.println("Sorry. Wrong choice");
        }
    }
}

Wednesday 25 March 2015


PROGRAM 5 : ENTER THE NUMBER OF ABUNDANT NUMBERS TO BE FOUND.

(Abundant number is number whose sum of all factors of that number(excluding number itself)is greater the number itself.
Example:  12 , 30 , 36 , 42)

PROGRAM:

import java.util.Scanner;
public class abundunt_number
{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        System.out.println("enter the number of abundunt numbers to be found:");
        int n = sc.nextInt();
        int counter = 0;
        for(int i = 10; counter<n ; i++){
            if (isabund(i)){
                System.out.print(i + " " );
                counter++;
            }
        }
    }
    public static boolean isabund(int a){
        int lim = a/2;
        int sum = 0;
        for(int i = 1 ; i<=lim ; i++){
            if(a%i==0){
                sum+=i;
            }
        }
        if(sum > a){
            return true;
        }
        else{
            return false;
        }
    }
}
PROGRAM FOR FUN!!!!!
JUST COPY IT ON JAVA FRIENDLY ENVIRONMENT LIKE BLUEJ AND SEE THE MAGIC.


PROGRAM:

import java.util.Scanner;
public class writer
{
    public static void main(String args[])throws InterruptedException{
        Scanner sc = new Scanner(System.in);
        int i;
        System.out.println("Enter a String to get repeated:");
        String str = sc.nextLine();
        for(i = 0 ; i<str.length() ; i++){
            System.out.print(str.charAt(i));
            Thread.sleep(200);
        }
    }
}


SEE IT FOR YOURSELF ;)
PROGRAM 4 : UNIQUE NUMBER

(UNIQUE NUMBER IS A NUMBER IN WHICH NO DIGIT IS REPEATED AND THE FIRST DIGIT IS NOT ZERO (0).
Example: 1234 , 45631 are unique numbers.

11234 , 15675 0987 , are not unique number as one or more digits occur more than once or the first digit is '0' )

PROGRAM:

import java.io.*;
public class unique_number
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a number to find out whether it is an unique number or not:");
        String s = br.readLine();
        int l = s.length() , f = 0;
        for(int i = 0 ; i < l ; i++){
            for(int j = i+1 ; j < l ; j++){
                if(s.charAt(i)==s.charAt(j) || s.charAt(0)=='0'){
                    f++;
                    break;
                }
            }
        }
        if(f==0)
          System.out.println("The number is an unique number.");
        else
          System.out.println("The number is not an unique number.");
        }
    }
PROGRAM 3 : PRIME PALINDROME - ENTER LOWER LIMIT AND UPPER LIMIT AND FIND ALL PRIME PALINDROME NUMBERS IN THAT PARTICULAR RANGE.

(Prime palindrome is number which is prime as well as palindrome in nature.
 Example : 11 , 111 )

PROGRAM:

import java.util.Scanner;
public class primepalindrome
{
    public static void main(String args[])
    { Scanner sc = new Scanner(System.in);
      System.out.println("Enter the upper and lower limit:");
      int x = sc.nextInt();
      int y = sc.nextInt();
      int i;
      System.out.println("All prime palindrome numbers:");
      for(i=x ; i<=y ; i++)
      {
          if(isprime(i)== true)
          {  if(ispalin(i)== true)
                 System.out.println(i);
                }
            }
        }
    public static boolean isprime(int i)
    {   int f = 0;
        for(int j = 2 ; j<i ; j++)
        {
            if(i%j==0)
               f++;
            }
        if(f==0)
           return(true);
        else
           return(false);
        }
    public static boolean ispalin(int i)
    {
        int dig;
        int ans = 0;
        int num = i;
        while(num>0)
        {
            dig = num%10;
            ans+= (ans*10)+dig;
            num = num/10;
        }
        if(num==i)
           return(true);
           else
              return (false);
        }
    }
 

Tuesday 24 March 2015

PROGRAM 2 : WAP TO ENTER A CHOICE IN WHICH '1' CHECKS WHETHER  NUMBER IS PRIME OR NOT AND '2' FOR CHECKING WHETHER NUMBER IS BUZZ NUMBER OR NOT.

(BUZZ number is a number which ends with digit '7' or is divisible by 7.
Example: 14 , 27 , 47 , 21 are BUZZ numbers.
 34 is not BUZZ number as it does not end with 7 or is divisible by 7)

PROGRAM:

import java.util.Scanner;
public class assign5
{
   public static void main(String args[]){
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter your choice: 1 for finding whether a number is prime or not and 2 for finding whether a number is BUZZ number or not.");
       int ch = sc.nextInt();
       int num;
       switch(ch)
       {
           case 1: System.out.println("enter a number to find out whether it is prime or not:");
                   num = sc.nextInt();
                    if(isprime(num)){
                       System.out.println("The number entered is a prime number.");
                    }
                    else{
                        System.out.println("The number entered is a prime number.");
                    }
           break;
           case 2: System.out.println("Enter a number  to find out whether it is BUZZ number or not:");
                   num = sc.nextInt();
                   if(isbuzz(num)){
                       System.out.println("The number entered is a BUZZ number.");
                    }
                    else{
                        System.out.println("The number entered is not a BUZZ number.");
                    }
           break;
           default: System.out.println("Sorry.Wrong choice!");
        }
    }
    public static boolean isprime(int n){
        int lim = n/2;
        int count = 0;
        for(int i = 2 ; i<=lim ; i++){
            if(n%i==0){
                count = 1;
                break;
            }
            else{
                count = 0;
            }
        }
        if(count == 1){
            return(false);
        }
        else{
            return(true);
        }
    }
    public static boolean isbuzz(int a){
        if( a%10==7 || a%7==0){
            return(true);
        }
        else{
            return(false);
        }
    }
}
 
Program 1 : PALINDROME NUMBER

PALINDROME NUMBER IS A NUMBER WHICH ON REVERSING REMAINS IN THE SAME ORDER.
EXAMPLE: 121 , 1441 , 153351

PROGRAM :

 import java.util.Scanner;
public class assign1
{
    public static void main(String args[]){
         Scanner sc = new Scanner(System.in);
         System.out.println("enter a number to find out whether it is a palindrome number or not:");
         int num = sc.nextInt();
         int q = num;
         int dig , r = 0;
         while(q!=0){
             dig = q%10;
             r = (r*10) + dig;
             q = q/10;
         }
         if(r==num){
             System.out.println("The number entered is palindrome.");
            }
         else {
             System.out.println("The number entered is not a palindrome");
            }
        }
    }