Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lab 5
- // Problem 1
- import java.util.*;
- public class Problem1{
- static void FindElement(int ...a){
- int min=a[0];
- for (int i=1; i<a.length; i++){
- if (a[i]<min) min=a[i];
- }
- System.out.println(min);
- }
- static void FindElement(double ...a){
- double max=a[0];
- for (int i=1; i<a.length; i++){
- if (a[i]>max) max=a[i];
- }
- System.out.println(max);
- }
- static void FindElement(char ...a){
- char c='A';
- for (int i=0; i<a.length-1; i++){
- for (int j=i+1; j<a.length; j++){
- if ((int)(a[i])>(int)(a[j])){
- c=a[i];
- a[i]=a[j];
- a[j]=c;
- }
- }
- }
- for (int i=0; i<a.length; i++){
- System.out.print(a[i]+" ");
- }
- System.out.println();
- }
- public static void main(String args[]){
- FindElement(5,6,2,4,7);
- FindElement(5.0,6.6,2.3,4.9,6.1);
- FindElement('E','I','Z','M');
- }
- }
- // Problem 2
- import java.util.*;
- public class Problem2{
- static int fib(int n){
- if (n==0) return 0;
- else if (n==1) return 1;
- return fib(n-1)+fib(n-2);
- }
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- while(t-->0){
- int n=sc.nextInt();
- System.out.println(fib(n));
- }
- }
- }
- // Problem 3
- import java.util.*;
- public class Problem3{
- private static int Front=0;
- private static int Rear=0;
- static int frontindex=0;
- static int rearindex=0;
- private static int a[]=new int[1000];
- public static void Enqueue(int n){
- if (rearindex==0){
- a[0]=n;
- Front=a[frontindex];
- Rear=a[rearindex];
- System.out.println("Front: " + Front);
- System.out.println("Rear: " + Rear);
- rearindex++;
- }
- else {
- a[rearindex]=n;
- Front=a[frontindex];
- Rear=a[rearindex];
- System.out.println("Front: " + Front);
- System.out.println("Rear: " + Rear);
- rearindex++;
- }
- }
- public static void Dequeue(){
- frontindex++;
- Front=a[frontindex];
- System.out.println("Front: " + Front);
- System.out.println("Rear: " + Rear);
- }
- public static void main(String args[]){
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- while(t-->0){
- // Modify the sequences of Enqueue and Dequeue operations accordingly
- for (int i=0; i<t; i++){
- int x=sc.nextInt();
- Enqueue(x);
- int y=sc.nextInt();
- Enqueue(y);
- Dequeue();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement