Hey guys, new here doing some work for my CIST 1400 so I'll most likely be posting a lot.
Anyway, I'm working on an octal conversion code that takes an octal number and converts it to a regular number in decimal using two methods( a main and convert method). So for my main(which is the validation) I have this code; we can't use string as that's beyond the material learned so far
It doesn't seem to compile as it gives me this error
The log10() method takes a double parameter and returns a double result. You can implicitly cast from int data type to double data type, which is why the method call is fine, but you can't implicitly cast the double result back to an int type.
How to fix? Well, first, determine if the int value is what you want, as you will lose precision. Once you determine that it is what you want, then you can explicitly cast the double type back to an int type.
So Math.log uses double types only then? Is there a way to validate without using Math.log, it seemed like a good idea but might be a little complicated to use now
Your line 6 doesn't give you an octal number. It gives you a number without 8 or 9 maybe, but in decimal. If you look through the Scanner documentation, you should find a way to correct that.
I am checking the length to validate and make sure the length isn't greater than 8. From my instructor
"Your program should prompt the user to enter a number of no greater than 8 digits. If they enter a number greater than 8 digits or a
value less than 0, it should re-prompt the user to enter a number again. You do not need to check if the digits are valid octal
numbers (0-7), as this is guaranteed."
All I am doing is making sure I have the length validation dwon as of now
Sorry everyone, maybe I'm not being specific enough.
An octal number is up to 8 digits long in length and uses numbers 0-7
What my assignment is basically having us do is use two methods; one to validate and one to confirm.
For validation i would have to check the following
1.) The number is 8 digits long
2.) Does not use any digit less than 0 or greater than 7
I thought that by using log I would be able to validate the length but maybe that's not the best solution.
Where is the number's value held? What kind of variable?
In decimal a number with less than 3 digits will have a value less than 100. 00 to 99
In octal a number with less than 3 digits will have a value less than 0100 (leading 0 says octal) 00 to 077
Then the number of digits for a number represented in an octal base can be tested for by using ranges of values. For example less than 2 digits would have a value less then 010.
Norm Radder wrote:Then the number of digits for a number represented in an octal base can be tested for by using ranges of values. For example less than 2 digits would have a value less then 010.
Think of decimal numbers. For the value in an int to have a single digit, its value must be less than 10. Two digits would be less than 100 and greater than 9 (10 to 99). In octal two digits would be less than 0100 and greater than 07.
Think of decimal numbers. For the value in an int to have a single digit, its value must be less than 10. Two digits would be less than 100 and greater than 9 (10 to 99). In octal two digits would be less than 0100 and greater than 07.
That makes sense, thank you.
Now when you said
Then the number of digits for a number represented in an octal base can be tested for by using ranges of values
I will; unrelated question. How long did it take for you and everyone else to get good at this? I appreciate the help greatly but often I end up being even more confused
I asked my instructor and though he said it varies from person to person he didn't give me a concrete answer as to how much I should be studying/practicing a day. Any suggestions for a frustrated newbie?
Sean Marquis wrote:. . . How long did it take for you and everyone else to get good at this? . . . how much I should be studying/practicing a day. Any suggestions for a frustrated newbie?
What are you doing? Are you a student? You will spend about 33%‑40% of your working week in lectures classes practicals or labs. Spend about half the remainder reading round the subject. And about half the remainder doing exercises directly related to it, including programming.
Yes, but I would check for errors rather than correct values:-Did you really write 09? That won't compile. Surely you mean 00? 0, 00, 0b0 (binary) and 0x0 (hexadecimal) should be regarded as interchangeable. The underscores in number literals were introduced in Java7.
Post by:autobot
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
a bit of art, as a gift, that will fit in a stocking