Skip to content
Snippets Groups Projects
Commit 4bce9401 authored by Benjamin Kvello-Hansen's avatar Benjamin Kvello-Hansen
Browse files

Update file oppgave2.java

parent 35673cc5
Branches main
No related tags found
No related merge requests found
import java.util.*;
public class oppgave2 {
static int primtallSjekk(int tall){
int primtall = 1;
for (int i = 2; i < tall; i = i + 1){
if (tall % i == 0){
primtall = 2;
break;
}
}
if (primtall == 1){
System.out.println("Tallet "+tall+" er et primtall");
}
else {
System.out.println("Tallet "+tall+" er ikke et primtall");
}
return primtall;
}
public static void main(String[] args){
int tall = 1;
while (tall != 0){
System.out.println("Hvilket tall vil du sjekke om er primtall? (skriv 0 for å avslutte) ");
Scanner inpTall = new Scanner(System.in);
tall = inpTall.nextInt();
primtallSjekk(tall);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment