Commit c8611a15 authored by mohammad.salama's avatar mohammad.salama

Creating Simple Finding Primes in Interval

parent 12c61a0c
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="156428c6-b9a7-4d3a-9504-b3537029ac6a" name="Changes" comment="" /> <list default="true" id="156428c6-b9a7-4d3a-9504-b3537029ac6a" name="Changes" comment="creat">
<change afterPath="$PROJECT_DIR$/src/main/java/SearchForPrimes.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/FindPrimesTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2XMJWqEVXOWOWiBZtLhpTJDKlyw" /> <component name="ProjectId" id="2XMJWqEVXOWOWiBZtLhpTJDKlyw" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
...@@ -16,9 +39,27 @@ ...@@ -16,9 +39,27 @@
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true" "RunOnceActivity.ShowReadmeOnStart": "true",
"last_opened_file_path": "D:/HIAST/FIY/FS/Parallel Programming/Lab/1/PP-lec01-Threads"
} }
}]]></component> }]]></component>
<component name="RunManager">
<configuration name="FindPrimesTest.testFindPrimes" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lab101" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="FindPrimesTest" />
<option name="METHOD_NAME" value="testFindPrimes" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.FindPrimesTest.testFindPrimes" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
...@@ -28,6 +69,29 @@ ...@@ -28,6 +69,29 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1698433053905</updated> <updated>1698433053905</updated>
</task> </task>
<task id="LOCAL-00001" summary="first">
<created>1698433083690</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1698433083690</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="first" />
<option name="LAST_COMMIT_MESSAGE" value="first" />
</component>
</project> </project>
\ No newline at end of file
...@@ -7,7 +7,13 @@ ...@@ -7,7 +7,13 @@
<groupId>org.example</groupId> <groupId>org.example</groupId>
<artifactId>Lab101</artifactId> <artifactId>Lab101</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
......
import java.util.ArrayList;
import java.util.List;
public class SearchForPrimes
{
private int start;
private int end;
private List<Integer> Primes;
public SearchForPrimes(int start, int end)
{
this.start = start;
this.end = end;
this.Primes = new ArrayList<>();
}
public List<Integer> getPrimes()
{
for (int i= this.start ; i <= this.end ; i++)
{
boolean isPrime = true;
for (int j=2 ; j*j <= i ; j++)
{
if (i%j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
Primes.add(i);
}
}
return this.Primes;
}
}
import junit.framework.TestCase;
import java.util.List;
public class FindPrimesTest extends TestCase
{
public void testFindPrimes()
{
SearchForPrimes searchForPrimes = new SearchForPrimes(1, 10000000);
long startTimer = System.currentTimeMillis();
List<Integer> Primes1 = searchForPrimes.getPrimes();
long endTimer = System.currentTimeMillis();
System.out.println("Time Taken = " + (endTimer-startTimer));
for (int i=0 ; i<Primes1.size() ; i++)
{
System.out.println(Primes1.get(i));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment