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

Thread: please tell me what's wrong in my program

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

    Question please tell me what's wrong in my program


    ok, i have recently learnt that 1729 is the only number that is the sum of two pairs of perfect cubes
    viz: 1^3 + 12^3 = 10^3 + 9^3 = 1729..
    But, i wasn't satisfied with this so I made a program to check.. Initially, i kept the ranges to be 1 to 100 , then changed it to 15 thinking whether 'int' would be enough for big numbers like 100^3... No matter what, it is supposed to show me 1729 (as 12<15)
    But, it doesn't!!
    Please tell me what mistake have I made... Because this program is not giving me any outputs..

    //Why is this program not working???

    public class Cubes
    {
    public static void main()
    {
    int[] a = new int[225];
    int t;
    for(int i=1; i<=15; i++)
    {
    for(int j=i; j<=15; j++)
    {
    t=i*i*i + j*j*j;
    for(int l=0;l<225; l++)
    {

    if(a[l]==t)
    {
    System.out.println(a[l]);
    }
    }
    for(int m=0; m<225; m++)
    {
    a[m] = t;
    }
    }
    }
    }
    }

    Please help me with this..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,616
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: please tell me what's wrong in my program

    this program is not giving me any outputs..
    Add some more calls to the println method to be sure the program shows what it is doing and has done.
    The Arrays class's toString() method is helpful for showing what's in an array:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Please help to understand whats the wrong with my guess. - Simple program
    By rayan2004 in forum Object Oriented Programming
    Replies: 1
    Last Post: December 14th, 2012, 12:03 AM
  2. Program returning wrong values.
    By cam25 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 11th, 2012, 11:59 PM
  3. Replies: 1
    Last Post: February 8th, 2012, 04:16 PM
  4. What's wrong with simple Scanner program?
    By SV25 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 21st, 2011, 07:05 AM
  5. whats wrong with my program??
    By jrodriguo in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 11th, 2010, 06:16 AM

Tags for this Thread