Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     //Public - могу получить доступ из любой части проекта
  5.     //Static - вызываю как octStringToInt, а не object.octStringToInt()
  6.     //int - return int
  7.     public static int octStringToInt(String s) {
  8.         int answer = Integer.parseInt(s,8);
  9.         return answer;
  10.     }
  11.  
  12.     public static boolean isNumeric(String s) {
  13.         for (char c : s.toCharArray())
  14.         {
  15.             if (!Character.isDigit(c))
  16.                 return false;
  17.         }
  18.         return true;
  19.     }
  20.  
  21.     public static int countNums(String s) {
  22.         int answer = 0;
  23.         for(String str : s.split(" ")) {
  24.             if(isNumeric(str))
  25.                 answer++;
  26.         }
  27.         return answer;
  28.     }
  29.  
  30.     public static void main(String[] agrs) {
  31.         System.out.println(octStringToInt("777"));
  32.         System.out.println(countNums("The user with the nickname koala757677 this month wrote 3 times more comments than the user with the nickname croco181dile920 4 months ago"));
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement