Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------Задача1-----------------------------------------
- import java.util.Scanner;
- public class BiggestDec {
- public static void main(String[] args) {
- Scanner scan= new Scanner(System.in);
- int num = scan.nextInt();
- int max= Integer.MIN_VALUE;
- while (num > 0){
- if (num%10 > max){
- max = num%10;
- }
- num/=10;
- }
- System.out.println(max);
- }
- }
- ------------------------------------Задача2-----------------------------------------
- import java.util.Scanner;
- public class SumOfNumbers {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int num = scan.nextInt();
- int sum = String.valueOf(num).length();
- System.out.println(sum);
- }
- }
- ------------------------------------Задача3-----------------------------------------
- public class CharNum {
- public static void main(String[] args) {
- char [] digits = {'1','5','9','1'};
- String digitsToString = String.valueOf(digits);
- int num = Integer.parseInt(digitsToString);
- System.out.println(num);
- }
- }
- ------------------------------------Задача4-----------------------------------------
- public class numberRecursion {
- static boolean ans = false;
- public static boolean isFound(int n, int target) {
- if (n == 0 || n%10 == target){
- if(n%10 == target){
- ans = true;
- }
- return ans;
- }else{
- isFound(n/10,target);
- }
- return ans;
- }
- public static void main(String[] args) {
- System.out.println(isFound(123,2));
- }
- }
- ------------------------------------Задача5-----------------------------------------
- public class OddEvenRecursion {
- static int even = 0;
- static int odd = 0;
- public static int oddEven(int n) {
- if (n != 0) {
- int curNum = n % 10;
- if (curNum % 2 == 0) {
- even++;
- } else {
- odd++;
- }
- oddEven(n / 10);
- } else {
- return Math.abs(odd - even);
- }
- return Math.abs(odd - even);
- }
- public static void main(String[] args) {
- System.out.println(oddEven(1952));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment