Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_Arraylist;
- public class stack {
- public static void main(String[] args) {
- StackOp m = new StackOp();
- m.push('S');
- m.push('O');
- m.push('V');
- m.push('L');
- m.push('E');
- m.push('D');
- m.showStack();
- m.pop();
- m.pop();
- m.pop();
- m.pop();
- m.showStack();
- m.showStack1();
- /*
- for(int i=6; i<=10; i++)
- {
- m.push('A');
- m.showStack();
- }
- for(int i=9; i>=-1; i--)
- {
- m.pop();
- m.showStack();
- }
- */
- }
- }
- class StackOp{
- char stck[] = new char[10];
- char stck1[] = new char[10];
- int tos;
- int tos1=-1;
- StackOp()
- {
- tos = -1;
- }
- void push(char item)
- {
- if(tos==9)
- {
- System.out.println("Stack Overflow");
- }
- else
- {
- stck[++tos] = item;
- }
- }
- char pop()
- {
- if(tos<0)
- {
- System.out.println("Stack underflow");
- return 0;
- }
- else
- {
- stck1[++tos1]=stck[tos];
- return stck[tos--];
- }
- }
- void showStack()
- {
- for(int i=0; i<=tos; i++)
- {
- System.out.print(stck[i]+" ");
- }
- System.out.println();
- }
- void showStack1()
- {
- for(int i=0; i<=1; i++)
- {
- System.out.print(stck[i]+" ");
- }
- for(int i=2; i<=3; i++)
- {
- System.out.print(stck1[i]+" ");
- }
- for(int i=1; i>=0; i--)
- {
- System.out.print(stck1[i]+" ");
- }
- }
- }
- arrayLIst
- package lab_Arraylist;
- import java.util.ArrayList;
- import java.util.Collections;
- public class arrayList {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ArrayList<String> student = new ArrayList<String>();
- student.add("Pranta Palit");
- student.add("Joy Chy");
- student.add("Akmam Khan");
- System.out.println("Listed Students: "+student);
- System.out.println("\nNumber of Students: "+student.size());
- student.set(2, "Akmam Chy");
- System.out.println("\n\nAfter Change: ");
- for(String i : student) //for-each loop
- {
- System.out.println(i);
- }
- Collections.sort(student); // Sorted list
- System.out.println("\n\nSorted list of Students(Ascending): "+student);
- student.remove(1);
- System.out.println("\n\nAnother use of loop: After removing student[1] ");
- for(int i=0; i<student.size(); i++)
- {
- System.out.println(student.get(i));
- }
- student.clear();
- System.out.println("\n\nAfter Clearing array list:");
- System.out.println(student);
- }
- }
- bank
- package lab5;
- import java.util.Scanner;
- public class task3 {
- public static double deposit(double amount) {
- Scanner ac=new Scanner(System.in);
- System.out.printf("enter diposit ammount ");
- double diposit =ac.nextDouble();
- double balance=amount+diposit;
- return balance;
- }
- public static double withdraw(double amount) {
- Scanner ac=new Scanner(System.in);
- if(amount<=0) {System.out.printf("in sufficient balance");
- return amount=0; }
- else
- System.out.printf("enter withdraw ammount ");
- double witdraw =ac.nextDouble();
- if( witdraw<500 && witdraw>20000 && witdraw>amount) {
- System.out.printf(" \nwrong trangection \n ");
- return amount;
- } else
- double balance = amount-witdraw;
- return balance;
- }
- public static void main(String[] args) {
- Scanner ac=new Scanner(System.in);
- // TODO Auto-generated method stub
- double balance =0;
- for( ; ; ) { System.out.println(" 1. Deposit\r\n" +
- "2. Withdraw\r\n" +
- "3. Balance\r\n" +
- "4. Exit ");
- int n=ac.nextInt();
- if(n==2) {
- balance =withdraw( balance);
- }
- else if(n==1) {
- balance=deposit( balance);
- }
- else if(n==3) {
- System.out.println("\nbalance " +balance);
- }
- else if(n==4) {
- System.exit(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement