MCPcopy Create free account
hub / github.com/Hazrat-Ali9/Computer-Programming / Problem11

Class Problem11

Problem11.java:5–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.util.Scanner;
4
5public class Problem11 {
6
7 public static void main(String[] args) {
8 // TODO Auto-generated method stub
9 Scanner input = new Scanner(System.in);
10 int T = input.nextInt();
11
12 while (T < 1) {
13 T = input.nextInt();
14 }
15 input.nextLine();
16 String[] inputs = new String[T];
17
18 for (int i = 0; i < inputs.length; i++) {
19 String temp = input.nextLine();
20 int length = temp.length();
21 while (length > 50 || !isDigit(temp.charAt(0)) || !isDigit(temp.charAt(temp.length() - 1))
22 || !isValid(temp)) {
23 temp = input.nextLine();
24 length = temp.length();
25 }
26 inputs[i] = temp;
27 }
28 input.close();
29
30 for (int i = 0; i < inputs.length; i++) {
31 StringBuilder myString = new StringBuilder(inputs[i]);
32
33 for (int j = 1; j < myString.length() - 1; j++) {
34 if (myString.charAt(j) == 'R') {
35
36 myString.setCharAt(j, myString.charAt(j + 1));
37 } else if (myString.charAt(j) == 'L') {
38 myString.setCharAt(j, myString.charAt(j - 1));
39 }
40 }
41 System.out.println(myString);
42 }
43
44 }
45
46 static boolean isDigit(char m) {
47 if (m >= 48 && m <= 57) {
48 return true;
49 } else {
50 return false;
51 }
52 }
53
54 static boolean isValid(String s) {
55 boolean res = true;
56 for (int i = 1; i < s.length() - 1; i++) {
57 if (s.charAt(i) == 'R' || s.charAt(i) == 'L') {
58 if (isDigit(s.charAt(i - 1)) && isDigit(s.charAt(i + 1))) {
59 res = true;
60 } else {
61 res = false;
62 return res;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected