BetinaUKTC

MopZadachi

Oct 25th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. ------------------------------------Задача1-----------------------------------------
  2. import java.util.Scanner;
  3.  
  4. public class BiggestDec {
  5. public static void main(String[] args) {
  6. Scanner scan= new Scanner(System.in);
  7. int num = scan.nextInt();
  8. int max= Integer.MIN_VALUE;
  9. while (num > 0){
  10. if (num%10 > max){
  11. max = num%10;
  12. }
  13. num/=10;
  14. }
  15. System.out.println(max);
  16. }
  17. }
  18. ------------------------------------Задача2-----------------------------------------
  19. import java.util.Scanner;
  20.  
  21. public class SumOfNumbers {
  22. public static void main(String[] args) {
  23. Scanner scan = new Scanner(System.in);
  24. int num = scan.nextInt();
  25. int sum = String.valueOf(num).length();
  26. System.out.println(sum);
  27. }
  28. }
  29. ------------------------------------Задача3-----------------------------------------
  30. public class CharNum {
  31. public static void main(String[] args) {
  32. char [] digits = {'1','5','9','1'};
  33. String digitsToString = String.valueOf(digits);
  34. int num = Integer.parseInt(digitsToString);
  35. System.out.println(num);
  36. }
  37. }
  38. ------------------------------------Задача4-----------------------------------------
  39. public class numberRecursion {
  40. static boolean ans = false;
  41. public static boolean isFound(int n, int target) {
  42. if (n == 0 || n%10 == target){
  43. if(n%10 == target){
  44. ans = true;
  45. }
  46. return ans;
  47. }else{
  48. isFound(n/10,target);
  49. }
  50. return ans;
  51. }
  52.  
  53. public static void main(String[] args) {
  54. System.out.println(isFound(123,2));
  55. }
  56. }
  57. ------------------------------------Задача5-----------------------------------------
  58. public class OddEvenRecursion {
  59. static int even = 0;
  60. static int odd = 0;
  61. public static int oddEven(int n) {
  62. if (n != 0) {
  63. int curNum = n % 10;
  64. if (curNum % 2 == 0) {
  65. even++;
  66. } else {
  67. odd++;
  68. }
  69. oddEven(n / 10);
  70. } else {
  71. return Math.abs(odd - even);
  72. }
  73. return Math.abs(odd - even);
  74. }
  75.  
  76. public static void main(String[] args) {
  77. System.out.println(oddEven(1952));
  78. }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment