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: Questions about a Problem I'm trying to solve

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Questions about a Problem I'm trying to solve

    [EDIT AND UPDATE]Thank you so much for your response. I was able to solve that using the modulus and if statements and having the != 0 for each number. It works and it's a huge strss reliever. I have another problem now I can't figure out. I've done three more after the last one, and this one seemed to have stumped me. If you can help out with it I will greaty appreciate it. ^^ Thanks again for the reply.


    "Design and write a Java application that takes as input an integer larger than 1 and calculates the sum of the squares from 1 to that integer. The output should be the value of the integer and the sum, properly labeled on screen. The application should repeat this process for several input values. Use a sentinel input value to end processing, and use screen input and output."

    Really the last part confuses me. Actually I'm not too good with using math in my coding. All help is GREATLY appreciated!

    Thank you for your time.
    Last edited by DarkEssence; March 16th, 2010 at 05:00 PM.


  2. #2
    Member Faz's Avatar
    Join Date
    Mar 2010
    Posts
    97
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Default Re: Questions about a Problem I'm trying to solve

    OK use of modulus and division is something that is often taught and if that's what they asked I would recomend you go that route. I'm not going to give the answer but I will help you break the problem down.

    First you know it's a 3 digit number.
    Second you need to check whether each of these numbers is odd or even.

    There are two ways I see that you could do this either write equations that will give you each individual digit and then check if each of those is odd or even.

    So in pseudocode
    Declare Variable for number and digits
    Set Number
    Set Digits
    Check Each digit for whether it is odd or even
    If all are odd display "All Odd"
    If all are even display "All Even"
    Else Display "Mixed"

    Now there is another way but I think learning this way would be more benificial to you. What you need to figure out is what the equation to find each digit. So lets start with the final digit lets say the 3 digit integer is 352 how are we going to get 2?

    First of all do you know how modulus works?

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Questions about a Problem I'm trying to solve

    Thank you so much for your response. I was able to solve that using the modulus and if statements and having the != 0 for each number. It works and it's a huge strss reliever. I have another problem now I can't figure out. I've done three more after the last one, and this one seemed to have stumped me. If you can help out with it I will greaty appreciate it. ^^ Thanks again for the reply.


    "Design and write a Java application that takes as input an integer larger than 1 and calculates the sum of the squares from 1 to that integer. The output should be the value of the integer and the sum, properly labeled on screen. The application should repeat this process for several input values. Use a sentinel input value to end processing, and use screen input and output."

    Really the last part confuses me. Actually I'm not too good with using math in my coding. All help is GREATLY appreciated!

    Thank you for your time.

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

  5. #5
    Member Faz's Avatar
    Join Date
    Mar 2010
    Posts
    97
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Default Re: Questions about a Problem I'm trying to solve

    Well as Darryl pointed out you will need a loop here (for or while eitehr will work). Also if the problem is that you don't know how to get the square root take a look at this

    Math (Java 2 Platform SE v1.4.2)

    Java has excellent documentation and tutorials on that site I would recommend that as your first port of call for problems like this. If it's the logic it can often help to define your problem step by step in English or even take a test case (define a number and work through step by step don't think about loops).

Similar Threads

  1. [SOLVED] Questions About Threads
    By neo_2010 in forum Threads
    Replies: 4
    Last Post: March 15th, 2010, 09:04 AM
  2. Java Questions! :)
    By xs4rdx in forum Java Theory & Questions
    Replies: 0
    Last Post: February 21st, 2010, 08:40 AM
  3. Some basic questions.
    By trips in forum Java Theory & Questions
    Replies: 5
    Last Post: July 21st, 2009, 02:15 AM
  4. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM