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: Desperte for your help

  1. #1
    Junior Member james's Avatar
    Join Date
    Jan 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Red face Desperte for your help

    Hey guys i have anther program here that really needs your help.
    Heres the question:
    Do the following programs:
    a) Write a program to display the sum of first 10 even numbers [2]
    b) Write a program that displays the total number of multiples of 7 between the
    numbers 1 and 100 [2]
    c) Write a program to add seven terms of the following series. 1! + 2! + 3! ................
    [3]

    public class quetion3a
    {
     public static void main(String[] args)
      {
       int num, sum;
       sum= 0;
       for (num=2; num<21; num=num+2)
            {
             sum=sum+num;
            }
       System.out.println("The sum of the first ten even numbers is "+sum);
      }
    }
    />
    Last edited by helloworld922; June 4th, 2010 at 07:10 PM. Reason: please use [code] tags

  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Desperte for your help

    Hey, whaddya think this is, a homework service?

    Here's a good tutorial that will help you (link below)
    The Java™ Tutorials

    db

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Desperte for your help

    We can help you write the code, but we won't write it for you. Post the code you have so far and explain what you are stuck on.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Desperte for your help

    For second part, perhaps

    int num1 = 1;
    int num2 = 1;
     
    while (num2 >=1 && num2 <= 100)
    {
    num2 = num1 % 7;
     
    if (num2 == 0)
    {
    isMultiple = true;
    System.out.println(num1);
    num2 = 1;
    num1 = num1 + 1;
     
    }
     
    else 
    {
    isMultiple = false;
    num1 = num1+ 1
    }
     
    }
    Last edited by helloworld922; June 4th, 2010 at 07:11 PM. Reason: please use [code] tags

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Desperte for your help

    For the third part,

    try something like

    int arrayOfStoredFactorials[] = new int [7];
     
    int list[] = new int[7];
     
    for (int a = 0;  a < 7; a++)
    {
    list[a] = a+1;
    }
     
    for (int i= 0;  i < 7 ; i++)
    {
    arrayOfStoredFactorials[i] = list[i];
     
     
    if (i > 0)
    {
    arrayOfFactorials[i] = list[i] * list[i-1];
    }
     
    }
     
    int sum = 0;
     
    for (int index = 0; index < arrayOfFactorials.length; index++)
    {
    sum = sum + arrayOfFactorials[index[;
    }
     
    System.out.println(sum);