Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nedpals/errgoengine
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 25, 2024
2 parents 2d9c33d + 2166995 commit 7b0546a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
String Reversal Utility
Description:
You're developing a feature for a text-editing app that reverses the input string from the user. This feature is crucial for certain text manipulation tasks but currently faces runtime exceptions, logic errors, and syntax issues.
Task:
Correct the issues causing runtime exceptions, logic errors, and syntax issues to ensure the feature can reverse a string successfully.
Example Output:
"dcba"
*/

public class ReverzeString {
public static void main(String[] args) {
String str = "abcd";
String reversed = reverse(str);
System.out.println(reversal);
}

public static String reverse(String s) {
String result = "";
for(int i = s.length(); i >= 0; i--) {
result += s.charAt(i);
}
return result;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "2"
template: "Java.PublicClassFilenameMismatchError"
---
ReverseString.java:14: error: class ReverzeString is public, should be declared in a file named ReverzeString.java
public class ReverzeString {
^
1 error
===
template: "Java.PublicClassFilenameMismatchError"
---
# PublicClassFilenameMismatchError
This error occurs because the name of the Java file does not match the name of the public class within it.
```

public class ReverzeString {
^^^^^^^^^^^^^
public static void main(String[] args) {
String str = "abcd";
```
## Steps to fix
### 1. Rename your file
Rename the file to "ReverzeString.java" to match the class.

### 2. Rename the public class
The filename should match the name of the public class in the file. To resolve this, change the class name to match the filename.
```diff
*/

- public class ReverzeString {
+ public class ReverseString {
public static void main(String[] args) {
String str = "abcd";
```

0 comments on commit 7b0546a

Please sign in to comment.