Answer the question
In order to leave comments, you need to log in
How to add a loop?
Hello.
For the university I do D / Z. It is necessary to write a program for reading numbers for simplicity.
Here's what happened:
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number: ");
int input = scan.nextInt();
boolean prime = true;
for (int i = 2; i<input; i++){
if(input % i==0){
prime = false;
}
}
if(prime==false){
System.out.println(input + " is not prime");
}
else if(prime==true){
System.out.println(input + " is prime");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question