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 5 of 5

Thread: I still have errors. Can you PLEASE correct my code?!

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I still have errors. Can you PLEASE correct my code?!

    An Emirp (prime spelled backward) is a prime number whose reversal is also a prime. For example, 17 is a prime 71 is a prime. So 17 and 71 are emirps. Write a program that displays the first 100 emirps. Display 10 numbers per line and align the numbers properly.

    import java.util.*;
     
    public class Exercise05_27{
     
    public static void main(String[] args){
    {int number=12,number2,upto=0,i;
    int[] prime=new int[100];
    while(upto<100)
    {if(!check(number,prime,upto))
    if(isPrime(number))
    {number2=reverse(number);
    if(number2!=number)
    if(!check(number2,prime,upto))
    if(isPrime(number2))
    upto=insert(number,number2,prime,upto);
    }
    number++;
    }
    sort(prime,upto);
    System.out.println("The first 100 EMIRP numbers are:");
    for(i=0;i
    {if(i%10==0)
    System.out.println();
    System.out.printf("%7d",prime[i]);
    }
    }
    }
    public static void sort(int a[],int n)
    {int i,j,t;
    for(i=0;i
    for(j=i;j
    if(a[i]>a[j])
    {t=a[i];
    a[i]=a[j];
    a[j]=t;
    }
    }
    public static boolean check(int n,int a[],int c)
    {int i;
    for(i=0;i
    if(a[i]==n)
    return true;
    return false;
    }
    public static int insert(int n,int m,int a[],int i)
    {
    a[i++]=n;
    a[i++]=m;
    return i;
    }
    public static int reverse(int n)
    {int newnum=0;
    while(n>0)
    {newnum=newnum*10+n%10;
    n=n/10;
    }
    return newnum;
    }
    public static boolean isPrime(int n)
    {int i;
    for(i=2;i
    if(n%i==0)
    false;
    Last edited by helloworld922; April 18th, 2011 at 08:53 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I have the program written, but I still have errors. Can you PLEASE correct my co

    In the future could you post your code you code in the body of the text rather than putting it into an attachment? Many people are wary of opening attachments. Posting your code in the body also makes reading the code in context a lot easier. Also, please format your text in a more readable fashion. If you're unsure of how to do this, I would suggest reading Java Code Conventions.

    Many popular IDE's have tools which will automatically format your code for you.

    What problems are you running into (compile errors, runtime errors, wrong results, etc.)? Could you post the outputs (including any error messages)?
    Last edited by helloworld922; April 18th, 2011 at 08:56 PM.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: I still have errors. Can you PLEASE correct my code?!

    After looking over your code, there are quite a lot of errors.. The main issues are with your for loops.

    I suggest you read - The for Statement (The Java Tutorials > Learning the Java Language > Language Basics)
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member benglish's Avatar
    Join Date
    Feb 2011
    Location
    LUV country
    Posts
    21
    My Mood
    Busy
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I still have errors. Can you PLEASE correct my code?!

    Besides, choose a better coding style!
    Your code follows no indentations!
    Falling in LUV is awfully simple, but falling out of LUV is simply awful

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    12
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: I still have errors. Can you PLEASE correct my code?!

    Quote Originally Posted by benglish View Post
    Besides, choose a better coding style!
    Your code follows no indentations!
    Yes, this was stated as the first response.

    @OP:
    Quote Originally Posted by JavaPF View Post
    After looking over your code, there are quite a lot of errors.. The main issues are with your for loops.

    I suggest you read - The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 02:32 PM
  2. I NEED A WRITTEN CODE
    By samy222 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 22nd, 2010, 05:28 PM
  3. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 05:37 PM
  4. My program doesnt want to do its math point my errors out please
    By Redlight in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2010, 02:56 PM
  5. need this program written
    By damajicman3 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2010, 04:19 PM