Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class dos
- {
- public static Scanner sc = new Scanner(System.in);
- public static Scanner leer = new Scanner(System.in);
- public static void main(String [] args)
- {
- System.out.println(areConsecutiveFibo(3,5)); //2
- System.out.println();
- triangle("filomena"); //3
- System.out.println();
- printDigitsAlphabets("Mexicali(2278)&Calexico(2122)+@=$"); //3 OR
- System.out.println();
- System.out.println(numberMinutesOfTrip(800,1510)); //4
- System.out.println();
- double[] array= {3,5,1,2,6,0};
- array=smallestAndBiggest(array); //5
- for(int i=0; i<array.length;i++)
- {
- System.out.print(array[i]+" ");
- }
- }
- public static boolean areConsecutiveFibo(int a, int b)
- {
- int n1=0, n2=1, n3=0;
- boolean cons=false;
- while(n3<=b)
- {
- if(a==n1&&b==n2)
- {
- cons=true;
- break;
- }
- n3=n1+n2;
- n1=n2;
- n2=n3;
- }
- return cons;
- }
- public static void triangle (String word)
- {
- char mid=word.charAt(word.length()/2);
- System.out.println(" "+mid);
- int left=word.length()/2-1;
- int right=word.length()/2+1;
- String space=" ";
- while(left>=0&&right<=word.length()-1)
- {
- for(int i=0; i<left; i++)
- {
- System.out.print(" ");
- }
- System.out.println(word.charAt(left)+space+word.charAt(right));
- left--;
- right++;
- space+=" ";
- }
- if(word.length()%2==0)
- {
- System.out.println(word.charAt(0));
- }
- }
- public static void printDigitsAlphabets(String word)
- {
- String newWord="";
- for(int i=0; i<word.length();i++)
- {
- if(Character.isDigit(word.charAt(i)))
- {
- newWord+=word.charAt(i);
- }
- }
- for(int i=0; i<word.length();i++)
- {
- if(Character.isLetter(word.charAt(i)))
- {
- newWord+=word.charAt(i);
- }
- }
- System.out.println(newWord);
- }
- public static int numberMinutesOfTrip (int a, int b)
- {
- int minutes=0,hours=0;
- if(a>b)
- {
- hours=24-a/100;
- if(a%100>0)
- {
- minutes=60-a%100;
- hours--;
- }
- minutes=minutes+b%100;
- }
- else
- {
- hours=b/100-a/100;
- minutes=a%100+b%100;
- }
- int time=hours*60+minutes;
- return time;
- }
- public static double[] smallestAndBiggest(double[] array)
- {
- double[] newArray= new double [2];
- double min=array[0], max=array[1];
- for(int i=0; i<array.length;i++)
- {
- if(min>array[i])
- {
- min=array[i];
- }
- if(max<array[i])
- {
- max=array[i];
- }
- }
- newArray[0]=min;
- newArray[1]=max;
- return newArray;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement