3 Commits
Author SHA1 Message Date
MehrdadShirvani 73ab04b5df Merge PR 'develop' (#1) from develop into main - Full Mark 100/100
Full Mark 100/100
2026-05-15 12:45:02 +00:00
bitahajati de430d3ebe Doing Bonus exercises 2026-04-24 01:10:46 +03:30
bitahajati f88049c7c4 Doing main exercises 2026-04-21 12:25:10 +03:30
6 changed files with 208 additions and 22 deletions
+10
View File
@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/main/main.iml" filepath="$PROJECT_DIR$/main/main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
<module fileurl="file://$PROJECT_DIR$/test/test.iml" filepath="$PROJECT_DIR$/test/test.iml" />
</modules>
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
+96 -11
View File
@@ -19,8 +19,11 @@ public class BonusExercises {
- Can't have underscores - Can't have underscores
- Each segment (between dots) must follow same hyphen rules - Each segment (between dots) must follow same hyphen rules
*/ */
public boolean validateEmail(String email) { public boolean validateEmail(String email)
String regex = ""; // todo {
if(email == null) return false;
String regex = "^(?!.*\\.\\.)(?!.*@.*@)[^@.\\s][^@\\s]*@([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)*[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$";
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email); Matcher matcher = pattern.matcher(email);
@@ -38,8 +41,31 @@ public class BonusExercises {
If no match for a date is found in the string, return null. If no match for a date is found in the string, return null.
*/ */
public String findDate(String string) { public String findDate(String string)
// todo {
if(string.isEmpty()) return null;
String isoPattern = "\\d{4}-\\d{2}-\\d{2}";
Pattern isoP = Pattern.compile(isoPattern);
Matcher isoMatcher = isoP.matcher(string);
if(isoMatcher.find()) return isoMatcher.group();
String slashVariantPattern = "\\d{4}/\\d{2}/\\d{2}";
Pattern slashP = Pattern.compile(slashVariantPattern);
Matcher slashMatcher = slashP.matcher(string);
if(slashMatcher.find()) return slashMatcher.group();
String usPattern = "(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\\d{4}";
Pattern usP =Pattern.compile(usPattern);
Matcher usMatcher = usP.matcher(string);
if(usMatcher.find()) return usMatcher.group();
String ukPattern = "(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\\d{4}";
Pattern ukP =Pattern.compile(ukPattern);
Matcher ukMatcher = ukP.matcher(string);
if(ukMatcher.find()) return ukMatcher.group();
return null; return null;
} }
@@ -53,9 +79,40 @@ public class BonusExercises {
- at least one number and at least a special char "!@#$%^&*" - at least one number and at least a special char "!@#$%^&*"
- has no white-space in it - has no white-space in it
*/ */
public int findValidPasswords(String string) { public int findValidPasswords(String string)
// todo {
return -1; if(string.isEmpty()) return 0;
String[] words = string.split(" ");
int count = 0;
for(String word : words)
{
if(word.length() < 8) continue;
boolean hasUpper = false;
boolean hasLower = false;
boolean hasSpecialChar = false;
boolean hasNumber = false;
for(int i = 0; i < word.length(); i++)
{
char x = word.charAt(i);
if (x >= 'A' && x <= 'Z') hasUpper = true;
if (x >= 'a' && x <= 'z') hasLower = true;
if (x >= '0' && x <= '9') hasNumber = true;
}
if(word.toString().contains("!") || word.toString().contains("@")
|| word.toString().contains("#") || word.toString().contains("$")
|| word.toString().contains("%") || word.toString().contains("*")
|| word.toString().contains("^") || word.toString().contains("&"))
{
hasSpecialChar = true;
}
if(hasUpper && hasLower && hasNumber && hasSpecialChar) count++;
}
return count;
} }
/* /*
@@ -64,13 +121,41 @@ public class BonusExercises {
note: your implementation should be case-insensitive, e.g. Aba -> is palindrome note: your implementation should be case-insensitive, e.g. Aba -> is palindrome
*/ */
public List<String> findPalindromes(String string) {
public boolean isPalindrome(String n)
{
String a = n.toLowerCase();
boolean isEqual = true;
for(int i = 0; i < (a.length()) / 2; i++)
{
if(a.charAt(i) != a.charAt(n.length() - 1 - i))
{
isEqual = false;
break;
}
}
if(isEqual) return true;
return false;
}
public List<String> findPalindromes(String string)
{
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
// todo
if(string.isEmpty()) return list;
String[] words = string.split(" ");
for(int i = 0; i < words.length; i++)
{
String newWord = words[i].replaceAll("[^a-zA-Z0-9]", "");
if(newWord.length() < 3) continue;
else if(isPalindrome(newWord) == true) list.add(newWord);
}
return list; return list;
} }
public static void main(String[] args) { public static void main(String[] args)
// you can test your code here {
} }
} }
+80 -11
View File
@@ -1,3 +1,6 @@
import java.util.ArrayList;
import java.util.List;
public class MainExercises public class MainExercises
{ {
/* /*
@@ -18,11 +21,21 @@ public class MainExercises
the output has to be a two-dimensional array of characters, so don't just print the triangle! the output has to be a two-dimensional array of characters, so don't just print the triangle!
*/ */
public char[][] generateTriangle(int n) { public char[][] generateTriangle(int n)
{
// todo char[][] triangle = new char[n][];
return null; for(int i = 0; i < n; i++)
{
triangle[i] = new char[i+1];
for(int j = 0; j <= i; j++)
{
if(i == 0 || j == 0 || i == j || i == n-1)
triangle[i][j] = '*';
else
triangle[i][j] = ' ';
}
}
return triangle;
} }
@@ -57,9 +70,38 @@ public class MainExercises
- Number of rows: matrix.length - Number of rows: matrix.length
- Number of columns: matrix[0].length (if rectangular) - Number of columns: matrix[0].length (if rectangular)
*/ */
public int[] spiralTraversal(int[][] matrix) { public int[] spiralTraversal(int[][] matrix)
// todo {
return null;
int m = matrix.length;
int n = matrix[0].length;
int x = 0;
int y = 0;
int idx = 0;
int[] numbers = new int[m * n];
boolean[][] visitedCell = new boolean[m][n];
int[][] dir = {{0,1},{1,0},{0,-1},{-1,0}};
for(int i = 0; i < (m * n); i++)
{
numbers[i] = matrix[x][y];
visitedCell[x][y] = true;
int nextX = x + dir[idx][0];
int nextY = y + dir[idx][1];
if (nextX < 0 || nextX >= m || nextY < 0 || nextY >= n || visitedCell[nextX][nextY] == true)
{
idx = (idx + 1) % 4;
nextX = x + dir[idx][0];
nextY = y + dir[idx][1];
}
x = nextX;
y = nextY;
}
return numbers;
} }
/* /*
@@ -90,11 +132,38 @@ public class MainExercises
body to use them instead of arrays. body to use them instead of arrays.
*/ */
public int[][] intPartitions(int n) { public int[][] intPartitions(int n)
// todo {
return null; List<int[]> result = new ArrayList<>();
findPartitions(n, n, new ArrayList<>(), result);
return result.toArray(new int[result.size()][]);
} }
private void findPartitions(int r, int max, List<Integer> list, List<int[]> finalList)
{
if (r == 0)
{
int[] partition = new int[list.size()];
for (int i = 0; i < list.size(); i++)
{
partition[i] = list.get(i);
}
finalList.add(partition);
return;
}
if (r >= max)
{
list.add(max);
findPartitions(r - max, max, list, finalList);
list.remove(list.size() - 1);
}
if (max > 1)
{
findPartitions(r, max - 1, list, finalList);
}
}
public static void main() public static void main()
{ {