Results 1 to 11 of 11
  1. #1
    cyzash is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Question How to Determine prime number and making shape using loop?

    Hi!:D
    I hav 2 question:

    1.How to determine all the prime numbers from 0 until the positive integer given by user?

    2. How to display this shape using java?

    *
    ***
    *****
    *******
    *********
    ***
    ***
    *********
    ..:cool::confused:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I hav 2 question:

    1.How to determine all the prime numbers from 0 until the positive integer given by user?

    2. How to display this shape using java?

    *
    ***
    *****
    *******
    *********
    ***
    ***
    *********
    and...

    3. How to ask a question here that shows you've put even a minimal amount of effort towards first trying to answer it yourself.

    Please understand that no one is going to do your homework for you, but we'll more than gladly try to help you with your work, providing of course that you first show us this work.

    Much luck!
    Last edited by Fubarable; 02-20-2010 at 05:51 AM.

  3. #3
    cyzash is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    Sorry, I'm not asking people to do my homework-i'm currently doing it.

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    then if you are having trouble with a specific part, feel free to ask for help.

  5. #5
    cyzash is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    ok...thanx..i don't realize dat it's wrong just to put the question only..

  6. #6
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    It's not wrong to only put a question, but people here want to help you learn java, not do homework for you. we usually feel that by answering broad questions like "how to make a program that does ..." is doing homework for the asker, and does not teach them anything. We are more inclined to answer questions that have to do with specific problems in your java program like, "I'm getting an error that says '...', here is my code, what am I doing wrong."

  7. #7
    cyzash is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    i see...sorry again if i made people to misunderstand the post.honestly no intention to ask people doing myhomework- :(

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by collin389 View Post
    It's not wrong to only put a question,...
    For this type of question, the classic "homework dump", I think that it is wrong since the poster isn't really asking a question at all but rather posting a restatement of the entire homework task itself without showing a bit of work.

    ...but people here want to help you learn java, not do homework for you. we usually feel that by answering broad questions like "how to make a program that does ..." is doing homework for the asker, and does not teach them anything. We are more inclined to answer questions that have to do with specific problems in your java program like, "I'm getting an error that says '...', here is my code, what am I doing wrong."
    This I fully agree with.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by cyzash View Post
    i see...sorry again if i made people to misunderstand the post.honestly no intention to ask people doing myhomework- :(
    No problem as you're learning both programming and forum etiquette at the same time. Both will get much better with time, I'm sure.

  10. #10
    cyzash is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    //hi this my code for checking n printing prime num
    //but still can't run
    //anybody know why?
    Java Code:
    public void checkNum(int inpNum){
     int isPrime=inpNum;
     int counter=0;
     for(int z=0;z<=isPrime;z++){
         for(int y=1;y<=isPrime;y++){
     if(z%y==0) {
         counter=counter+1;
          prime[j]=z;
          j++;
     }
     
     }if (counter==2) System.out.println(prime[j] +" ");}
     
    }
    Last edited by cyzash; 02-20-2010 at 08:04 AM. Reason: to apply code tag

  11. #11
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    Well, you never initialize j
    Also, your brute force method is OK I guess but there are much better ways like. Read this: Primality test - Wikipedia, the free encyclopedia
    It explains that you only need to check from m to sqrt(n) not n-1, also things like skipping the evens and things like that.

Similar Threads

  1. Prime Number - System print all the prime numbers ...
    By pinkdreammsss in forum New To Java
    Replies: 20
    Last Post: 04-26-2009, 01:50 AM
  2. prime numbers program
    By i contra i in forum New To Java
    Replies: 9
    Last Post: 01-15-2009, 07:22 AM
  3. Prime numbers
    By tercius in forum New To Java
    Replies: 3
    Last Post: 05-04-2008, 06:05 AM
  4. Prime numbers
    By gapper in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 10:09 AM
  5. how to determine the primary key
    By osval in forum JDBC
    Replies: 1
    Last Post: 08-07-2007, 02:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •