Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exam {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. System.out.println("Введите строку");
  8. String text = scanner.nextLine();
  9.  
  10. char[]chars = text.toCharArray();
  11. text = "";
  12.  
  13. for (int i = 0; i < chars.length; i++) {
  14. if (Character.isDigit(chars[i])) {
  15. text += " ";
  16. } else {
  17. text += chars[i];
  18. }
  19. }
  20.  
  21. System.out.println(text);
  22. }
  23. }
  24.  
  25. class NumberTwo {
  26. public static void main(String[] args) {
  27. Scanner scanner = new Scanner(System.in);
  28.  
  29. System.out.println("Введите строку");
  30. String text = scanner.nextLine();
  31.  
  32. char[]chars = text.toCharArray();
  33.  
  34. int openSymbol = 0;
  35. int closeSymbol = 0;
  36.  
  37. for (int i = 0; i < chars.length; i++) {
  38. if (chars[i] == '(') {
  39. openSymbol++;
  40. } else if (chars[i] == ')') {
  41. closeSymbol++;
  42. }
  43. }
  44.  
  45. if (openSymbol == closeSymbol) {
  46. System.out.println("количество открывающихся и закрывающихся скобок совпадает");
  47. } else if (openSymbol > closeSymbol) {
  48. System.out.println("Количество открывающихся скобок больше, чем закрывающихся");
  49. } else {
  50. System.out.println("Количество закрыващихся скобок больше, чем открываюищхся");
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement