Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import java.util.*;
  2. class dos
  3. {
  4. public static Scanner sc = new Scanner(System.in);
  5. public static Scanner leer = new Scanner(System.in);
  6. public static void main(String [] args)
  7. {
  8. System.out.println(areConsecutiveFibo(3,5)); //2
  9. System.out.println();
  10. triangle("filomena"); //3
  11. System.out.println();
  12. printDigitsAlphabets("Mexicali(2278)&Calexico(2122)+@=$"); //3 OR
  13. System.out.println();
  14. System.out.println(numberMinutesOfTrip(800,1510)); //4
  15. System.out.println();
  16. double[] array= {3,5,1,2,6,0};
  17. array=smallestAndBiggest(array); //5
  18. for(int i=0; i<array.length;i++)
  19. {
  20. System.out.print(array[i]+" ");
  21. }
  22. }
  23.  
  24. public static boolean areConsecutiveFibo(int a, int b)
  25. {
  26. int n1=0, n2=1, n3=0;
  27. boolean cons=false;
  28. while(n3<=b)
  29. {
  30. if(a==n1&&b==n2)
  31. {
  32. cons=true;
  33. break;
  34. }
  35. n3=n1+n2;
  36. n1=n2;
  37. n2=n3;
  38. }
  39. return cons;
  40. }
  41.  
  42. public static void triangle (String word)
  43. {
  44. char mid=word.charAt(word.length()/2);
  45. System.out.println(" "+mid);
  46. int left=word.length()/2-1;
  47. int right=word.length()/2+1;
  48. String space=" ";
  49. while(left>=0&&right<=word.length()-1)
  50. {
  51. for(int i=0; i<left; i++)
  52. {
  53. System.out.print(" ");
  54. }
  55. System.out.println(word.charAt(left)+space+word.charAt(right));
  56. left--;
  57. right++;
  58. space+=" ";
  59. }
  60. if(word.length()%2==0)
  61. {
  62. System.out.println(word.charAt(0));
  63. }
  64.  
  65. }
  66.  
  67. public static void printDigitsAlphabets(String word)
  68. {
  69. String newWord="";
  70. for(int i=0; i<word.length();i++)
  71. {
  72. if(Character.isDigit(word.charAt(i)))
  73. {
  74. newWord+=word.charAt(i);
  75. }
  76. }
  77. for(int i=0; i<word.length();i++)
  78. {
  79. if(Character.isLetter(word.charAt(i)))
  80. {
  81. newWord+=word.charAt(i);
  82. }
  83. }
  84. System.out.println(newWord);
  85.  
  86. }
  87. public static int numberMinutesOfTrip (int a, int b)
  88. {
  89. int minutes=0,hours=0;
  90. if(a>b)
  91. {
  92. hours=24-a/100;
  93. if(a%100>0)
  94. {
  95. minutes=60-a%100;
  96. hours--;
  97. }
  98. minutes=minutes+b%100;
  99. }
  100. else
  101. {
  102. hours=b/100-a/100;
  103. minutes=a%100+b%100;
  104. }
  105. int time=hours*60+minutes;
  106. return time;
  107. }
  108.  
  109. public static double[] smallestAndBiggest(double[] array)
  110. {
  111. double[] newArray= new double [2];
  112. double min=array[0], max=array[1];
  113. for(int i=0; i<array.length;i++)
  114. {
  115. if(min>array[i])
  116. {
  117. min=array[i];
  118. }
  119. if(max<array[i])
  120. {
  121. max=array[i];
  122. }
  123. }
  124. newArray[0]=min;
  125. newArray[1]=max;
  126. return newArray;
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement