2 files modified
2 files added
| | |
| | | "vscjava.vscode-java-pack", // Java Extension Pack |
| | | "pivotal.vscode-spring-boot", // Spring support (opzionale) |
| | | "test-editor.test-editor", // Supporto ai test (opzionale) |
| | | "redhat.java" // Supporto al linguaggio Java |
| | | "redhat.java", // Supporto al linguaggio Java |
| | | "dotjoshjohnson.xml" // XML Tools |
| | | ] |
| | | } |
| | | } |
| | |
| | | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | | <groupId>com.example</groupId> |
| | |
| | | |
| | | <dependencies> |
| | | <!-- Add your project dependencies here --> |
| | | <dependency> |
| | | <groupId>org.junit.jupiter</groupId> |
| | | <artifactId>junit-jupiter</artifactId> |
| | | <version>5.10.0</version> |
| | | <scope>test</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | <target>25</target> |
| | | </configuration> |
| | | </plugin> |
| | | |
| | | <!-- Plugin per eseguire i test --> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-surefire-plugin</artifactId> |
| | | <version>3.2.5</version> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | </project> |
| New file |
| | |
| | | public class NumeroPrimo { |
| | | public boolean isPrimo(int numero) { |
| | | if (numero <= 1) { |
| | | return false; |
| | | } |
| | | if (numero % 2 == 0) { |
| | | return false; |
| | | } |
| | | for (int i = 3; i <= Math.sqrt(numero); i += 2) { |
| | | if (numero % i == 0) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | NumeroPrimo np = new NumeroPrimo(); |
| | | |
| | | int limite = Integer.parseInt(args[0]); |
| | | |
| | | long startTime = System.nanoTime(); |
| | | int conta = 1; |
| | | for (int i = 3; i <= limite; i += 2) { |
| | | if (np.isPrimo(i)) { |
| | | System.out.println(conta + " " + i); |
| | | conta++; |
| | | } |
| | | } |
| | | |
| | | long endTime = System.nanoTime(); // ⏱️ Fine |
| | | |
| | | long duration = endTime - startTime; // in nanosecondi |
| | | System.out.println("Tempo di esecuzione: " + (duration / 1_000_000) + " ms"); |
| | | } |
| | | } |
| New file |
| | |
| | | |
| | | import org.junit.jupiter.api.Test; |
| | | import static org.junit.jupiter.api.Assertions.*; |
| | | |
| | | public class NumeroPrimoTest { |
| | | |
| | | @Test |
| | | void testPrimo1() { |
| | | NumeroPrimo primo = new NumeroPrimo(); |
| | | assertEquals(false, primo.isPrimo(1)); |
| | | } |
| | | |
| | | @Test |
| | | void testPrimoNegativo() { |
| | | NumeroPrimo primo = new NumeroPrimo(); |
| | | assertEquals(false, primo.isPrimo(-101)); |
| | | } |
| | | |
| | | @Test |
| | | void testSomma() { |
| | | NumeroPrimo primo = new NumeroPrimo(); |
| | | assertEquals(true, primo.isPrimo(3)); |
| | | } |
| | | |
| | | @Test |
| | | void testSommaNegativi() { |
| | | NumeroPrimo primo = new NumeroPrimo(); |
| | | assertEquals(false, primo.isPrimo(4)); |
| | | } |
| | | } |