Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Error ? Jgrasp ...

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 !!!!!!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Error ? Jgrasp ...

    Quote Originally Posted by cukunit0 View Post
    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.

    but the question if different with my answer right?
    I have no idea what you are saying.
    Improving the world one idiot at a time!

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Error ? Jgrasp ...

    Hello.
    First, do you know what a prime number is?
    Your logic says you don't.

    Syed.

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    16
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default 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

    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
    }

Similar Threads

  1. Problems with A* Map Search - GC Overload Error and Null Error
    By puneeth.meruva in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2013, 03:01 PM
  2. Replies: 4
    Last Post: October 15th, 2013, 04:33 AM
  3. Is Java 7 not available with Jgrasp?
    By dougie1809 in forum Java IDEs
    Replies: 6
    Last Post: March 6th, 2013, 07:47 AM
  4. Please! Help me to this error "ERROR CANNOT FIND SYMBOL"
    By mharck in forum Object Oriented Programming
    Replies: 8
    Last Post: July 3rd, 2012, 09:20 AM
  5. Jgrasp issue
    By Joy123 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 28th, 2011, 10:39 PM