Results 1 to 2 of 2

Thread: array

  1. #1
    Join Date
    Jul 2010
    Rep Power

    Default array

    Please help me finding the error on my program. As stated below it needs to display the factorial of each 10 value in array.. But when I run this program it only display 1 value and 1 factorial. Please help on this. Thanks :)

    //Write a program that will input 10 integers then display the factorial of each value in array

    import javax.swing.*;
    public class factorial
    static int[] num=new int[10];
    public static void main(String args[])
    for (int loc=0;loc<num.length;loc++)
    num[loc]=Integer.parseInt(JOptionPane.showInputDialog("Ent er index of "+loc));
    display (num);
    public static void display(int a[])
    int facto=1;
    int x=1;
    String temp="";
    for(int loc=0;loc<a.length;loc++)
    temp+="\nIndex of "+loc+" "+a[loc];
    facto*=x; //I guess the problem is on this
    // part.. I need a code that
    } //will move to the next array...
    temp+="\nfacto is "+facto;
    JTextArea jt=new JTextArea(15,30);
    JScrollPane js=new JScrollPane(jt);
    Heart is the only broken thing that still works.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Your code is very hard to read. Please add the [code ] and [/code ] tags (no space) around it to preserve formatting.

    Also please add some comments to the code describing what each step of the code is supposed to do.

    it only display 1 value and 1 factorial
    Where/how does it display anything?

    For debugging add the following to show your results:
    System.out.println("num=" + Arrays.toString(num)); // show num values

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  3. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  4. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

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