Results 1 to 2 of 2

Thread: Simple java

  1. #1
    abhiN is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default Simple java

    Hi

    suppose i've

    int[] nos = new int[]{1 to 10};

    and
    int[] sum;

    then i want
    for(i =0 i{
    sum[i] = (sum of all nos other than i)
    }

    how to get ..
    plz reply..

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Hello

    Try this:
    Java Code:
    int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int[] sums = new int[numbers.length];
    for (int i = 0; i < numbers.length; i++){
        int sum = 0;
        for (int j = 0; j < numbers.length; j++){
            if (numbers[j] != numbers[i]){
                sum += numbers[j];
            }
        }
        sums[i] = sum;
    }
    Hope this does the trick! ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. 2 simple java questions
    By jimJohnson in forum New To Java
    Replies: 2
    Last Post: 02-02-2008, 10:35 AM
  2. I need simple java applet
    By silvia in forum Java Applets
    Replies: 4
    Last Post: 01-27-2008, 08:50 AM
  3. Simple java
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 01-16-2008, 03:44 PM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 09:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 10: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
  •