Skip to content

Commit 0c3facf

Browse files
committed
Added 'README.md' file and some solutions
1 parent 702d499 commit 0c3facf

File tree

9 files changed

+98
-0
lines changed

9 files changed

+98
-0
lines changed

.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
/bin/

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Java DSA Assignments</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=16
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=16

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Java-DSA-Assignments

src/strings/CountMatches.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package strings;
2+
3+
import java.util.List;
4+
5+
public class CountMatches {
6+
public static int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
7+
int count = 0;
8+
int index = 0;
9+
if(ruleKey.equals("color")) index = 1;
10+
else if(ruleKey.equals("name")) index = 2;
11+
for (List<String> arr : items) {
12+
if(arr.get(index).equals(ruleValue)) count++;
13+
}
14+
return count;
15+
}
16+
}

src/strings/DefangIPAddress.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package strings;
2+
3+
public class DefangIPAddress {
4+
public static void main(String[] args) {
5+
String ip = "1.1.1.1";
6+
System.out.println(ip);
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package strings;
2+
3+
public class GoalParserInterception {
4+
public static void main(String[] args) {
5+
String command = "(al)G(al)()()G";
6+
System.out.println(interpret(command));
7+
}
8+
9+
public static String interpret(String command) {
10+
command = command.replaceAll("\\(\\)", "o");
11+
command = command.replaceAll("\\(al\\)", "al");
12+
return command;
13+
}
14+
}

src/strings/RestoreString.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package strings;
2+
3+
public class RestoreString {
4+
public static void main(String[] args) {
5+
String s = "codeleet";
6+
int[] indices = {4,5,6,7,0,2,1,3};
7+
System.out.println(restoreString(s, indices));
8+
}
9+
10+
public static String restoreString(String s, int[] indices) {
11+
StringBuilder builder = new StringBuilder(s);
12+
for (int i = 0; i < indices.length; i++) {
13+
builder.setCharAt(indices[i], s.charAt(i));
14+
}
15+
return builder.toString();
16+
}
17+
}

0 commit comments

Comments
 (0)