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
Visit My Blog: http://vinay-kumar-saini.blogspot.in/
/*
* Java Program to Implement Stack
*/
import java.util.*;
/* Class arrayStack */
class arrayStack
{
protected int arr[];
protected int top, size, len;
/* Constructor for arrayStack */
public arrayStack(int n)
{
size = n;
len = 0;
arr = new int[size];
top = -1;
}
/* Function to check if stack is empty */
public boolean isEmpty()
{
return top == -1;
}
/* Function to check if stack is full */
public boolean isFull()
{
return top == size -1 ;
}
/* Function to get the size of the stack */
public int getSize()
{
return len ;
}
/* Function to check the top element of the stack */
public int peek()
{
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
return arr[top];
}
/* Function to add an element to the stack */
public void push(int i)
{
if(top + 1 >= size)
throw new IndexOutOfBoundsException("Overflow Exception");
if(top + 1 < size )
arr[++top] = i;
len++ ;
}
/* Function to delete an element from the stack */
public int pop()
{
if( isEmpty() )
throw new NoSuchElementException("Underflow Exception");
len-- ;
return arr[top--];
}
/* Function to display the status of the stack */
public void display()
{
System.out.print("\nStack = ");
if (len == 0)
{
System.out.print("Empty\n");
return ;
}
for (int i = top; i >= 0; i--)
System.out.print(arr[i]+" ");
System.out.println();
}
}
/* Class StackImplement */
public class StackImplement
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Stack Test\n");
System.out.println("Enter Size of Integer Stack ");
int n = scan.nextInt();
/* Creating object of class arrayStack */
arrayStack stk = new arrayStack(n);
/* Perform Stack Operations */
char ch;
do{
System.out.println("\nStack Operations");
System.out.println("1. push");
System.out.println("2. pop");
System.out.println("3. peek");
System.out.println("4. check empty");
System.out.println("5. check full");
System.out.println("6. size");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("Enter integer element to push");
try
{
stk.push( scan.nextInt() );
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 2 :
try
{
System.out.println("Popped Element = " + stk.pop());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 3 :
try
{
System.out.println("Peek Element = " + stk.peek());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 4 :
System.out.println("Empty status = " + stk.isEmpty());
break;
case 5 :
System.out.println("Full status = " + stk.isFull());
break;
case 6 :
System.out.println("Size = " + stk.getSize());
break;
default :
System.out.println("Wrong Entry \n ");
break;
}
/* display stack */
stk.display();
System.out.println("\nDo you want to continue (Type y or n) \n");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}
Visit My Blog: http://vinay-kumar-saini.blogspot.in/
No comments:
Post a Comment