Program List for Basic Logic Development

1.       Write a program that takes input of student's marks in five subjects(out of 100) and print the percentage
2.       Write a program to convert given number of days into years, weeks and days
3.       Write a program to find minimum of three numbers using conditional operator
4.       Write a program to print the largest of three numbers.(only if)
5.       Write a program to print the mathematical table of a number
6.       Write a program to display the name of the month depends upon the number (between 1-12) be enter by the user.(switch)
7.        Write a program to check whether a entered year is leap year or not.
8.       Write a program to find the sum of first “n “natural numbers
9.       Write a program to find the factorial value of a number entered by the user.
10.   Write a program to find the value of “m” to the power “n”.
11.   Write a program to print the Fibonacci series of specified terms (0 1 1 2 3 5 ………)
12.   Write a program to find sum of all the digits of a given number.(while)
13.   Write a program to check whether the number is prime or not.
14.   Write a program to check whether a number is palindrome or not.
15.   Find GCD and LCM of two numbers
16.   Write a program to print the given figure:
                                               *
                                           *  *  *
                                        *  *  *  *  *
                                    *  *  *  *  *  *  *
17.   Write a program to check whether a character is an alphabet or not and also check its Case
18.   Write a program that reads a string and converts case of each character in the string
19.   Write a program that reads a string and a character and Count the number of occurrence of the character in the given string
20.   To swap two numbers
21.   To check whether the given character is present in the string
22.   To find minimum of three numbers
23.   Write a program to find the largest and smallest element in an array
24.    Write a program to arrange the array elements in ascending order.
25.   Write a program to search a specified element in a given array.
26.   To find largest element of an Array (using function)
27.   To check if a string is a palindrome or not
28.   To count number of words,characters, vowels in a given string
29.   Write a program to add two matrices.
30.   Write a program to find the product of two matrices.
31.   To find Transpose of a matrix
32.   Write a program to find the sum of left and right diagonal of a 3x3 matrix
33.   Write a program to make a structure of student with the following details. (Name,Age,Class,Marks, Average, Result)& Get Input from the user for the data Name, Age, Class Marks and Find the average & result of the student if average>=40 result ‘P’ if not result ‘F’
34.   Convert decimal to binary
35.   Swap two numbers without using third variable
36.   To display substring of a given string
37.   Armstrong Number Checking
38.   Finding Prime numbers in a given range
39.   To remove duplicates in a an array
40.   Write a program to print the given figure
A
A B
A B C
A B C D



  1. /*
  2.  * Java Program to Implement Stack
  3.  */
  4.  
  5. import java.util.*;
  6.  
  7. /*  Class arrayStack  */
  8. class arrayStack
  9. {
  10.     protected int arr[];
  11.     protected int top, size, len;
  12.     /*  Constructor for arrayStack */
  13.     public arrayStack(int n)
  14.     {
  15.         size = n;
  16.         len = 0;
  17.         arr = new int[size];
  18.         top = -1;
  19.     }
  20.     /*  Function to check if stack is empty */
  21.     public boolean isEmpty()
  22.     {
  23.         return top == -1;
  24.     }
  25.     /*  Function to check if stack is full */
  26.     public boolean isFull()
  27.     {
  28.         return top == size -1 ;        
  29.     }
  30.     /*  Function to get the size of the stack */
  31.     public int getSize()
  32.     {
  33.         return len ;
  34.     }
  35.     /*  Function to check the top element of the stack */
  36.     public int peek()
  37.     {
  38.         if( isEmpty() )
  39.             throw new NoSuchElementException("Underflow Exception");
  40.         return arr[top];
  41.     }
  42.     /*  Function to add an element to the stack */
  43.     public void push(int i)
  44.     {
  45.         if(top + 1 >= size)
  46.             throw new IndexOutOfBoundsException("Overflow Exception");
  47.         if(top + 1 < size )
  48.             arr[++top] = i;
  49.         len++ ;
  50.     }
  51.     /*  Function to delete an element from the stack */
  52.     public int pop()
  53.     {
  54.         if( isEmpty() )
  55.             throw new NoSuchElementException("Underflow Exception");
  56.         len-- ;
  57.         return arr[top--]; 
  58.     }    
  59.     /*  Function to display the status of the stack */
  60.     public void display()
  61.     {
  62.         System.out.print("\nStack = ");
  63.         if (len == 0)
  64.         {
  65.             System.out.print("Empty\n");
  66.             return ;
  67.         }
  68.         for (int i = top; i >= 0; i--)
  69.             System.out.print(arr[i]+" ");
  70.         System.out.println();
  71.     }    
  72. }
  73.  
  74. /*  Class StackImplement  */
  75. public class StackImplement
  76. {
  77.     public static void main(String[] args)
  78.     {
  79.         Scanner scan = new Scanner(System.in);        
  80.         System.out.println("Stack Test\n");
  81.         System.out.println("Enter Size of Integer Stack ");
  82.         int n = scan.nextInt();
  83.         /* Creating object of class arrayStack */
  84.         arrayStack stk = new arrayStack(n);
  85.         /* Perform Stack Operations */
  86.         char ch;
  87.         do{
  88.             System.out.println("\nStack Operations");
  89.             System.out.println("1. push");
  90.             System.out.println("2. pop");
  91.             System.out.println("3. peek");
  92.             System.out.println("4. check empty");
  93.             System.out.println("5. check full");
  94.             System.out.println("6. size");
  95.             int choice = scan.nextInt();
  96.             switch (choice)
  97.             {
  98.             case 1 : 
  99.                 System.out.println("Enter integer element to push");
  100.                 try 
  101.                 {
  102.                     stk.push( scan.nextInt() );
  103.                 }
  104.                 catch (Exception e)
  105.                 {
  106.                     System.out.println("Error : " + e.getMessage());
  107.                 }                         
  108.                 break;                         
  109.             case 2 : 
  110.                 try
  111.                 {
  112.                     System.out.println("Popped Element = " + stk.pop());
  113.                 }
  114.                 catch (Exception e)
  115.                 {
  116.                     System.out.println("Error : " + e.getMessage());
  117.                 }    
  118.                 break;                         
  119.             case 3 :         
  120.                 try
  121.                 {
  122.                     System.out.println("Peek Element = " + stk.peek());
  123.                 }
  124.                 catch (Exception e)
  125.                 {
  126.                     System.out.println("Error : " + e.getMessage());
  127.                 }
  128.                 break;                         
  129.             case 4 : 
  130.                 System.out.println("Empty status = " + stk.isEmpty());
  131.                 break;                
  132.             case 5 :
  133.                 System.out.println("Full status = " + stk.isFull());
  134.                 break;                 
  135.             case 6 : 
  136.                 System.out.println("Size = " + stk.getSize());
  137.                 break;                         
  138.             default : 
  139.                 System.out.println("Wrong Entry \n ");
  140.                 break;
  141.             }
  142.             /* display stack */
  143.             stk.display();            
  144.             System.out.println("\nDo you want to continue (Type y or n) \n");
  145.             ch = scan.next().charAt(0);
  146.  
  147.         } while (ch == 'Y'|| ch == 'y');                 
  148.     }
  149. }


Visit My Blog: http://vinay-kumar-saini.blogspot.in/

No comments:

Post a Comment