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