# Error ? Jgrasp ...

• November 13th, 2013, 09:42 PM
cukunit0
Error ? Jgrasp ...
The question is....
Write a program that, given an integer input, can display whether the input is a prime number or not. To do this, you must define a method named isPrime that receives an integer as its parameter and will return true if the integer is a prime number. Otherwise, it will return false. Your program will then call this method for the displaying purpose.

This is my code...
import java.util.Scanner;
public class main1 {

public static void main(String[] args) {

Scanner abc;
abc = new Scanner (System.in);
int input;
int divide = 2;
int count=0;

System.out.println("Please enter an interger to determine if it is prime");
input = abc.nextInt();

for (int x=1; x < input; x++) {
if ((input%divide) == 0)
count += 1;
divide = divide + 1;
}

if (count == 0)
System.out.println("It is a prime number");
else
System.out.println("It is not a prime number");
}
}

but the question if different with my answer right?
SO what should i write for this question...

In JGRASP !! not C or C++ ..

THANKS !!!!!!
• November 13th, 2013, 10:05 PM
Junky
Re: Error ? Jgrasp ...
Quote:

Originally Posted by cukunit0
In JGRASP !! not C or C++

Jgrasp is an IDE and not a programming language. That is like saying I'll have pine timber and not a hammer or chisel.

Quote:

but the question if different with my answer right?
I have no idea what you are saying.
• November 14th, 2013, 07:15 AM
syedbhai
Re: Error ? Jgrasp ...
Hello.
First, do you know what a prime number is?

Syed.
• November 14th, 2013, 07:52 AM
Re: Error ? Jgrasp ...
PRIME Number is one which is divide only by it self and 1. now make your logic to find the Prime number . but the programme should be look like this

Code :

int input;
Scanner myscan = new Scanner(System.in);
input = myscan.nextInt();

if(isPrime(input))
System.out.print("This is Prime Number");
else
System.out.print("Not Prime");

public boolean isPrime(int a){
if( // PRIME Number Logic  ) return true;
else return false
}