I'm reviewing for my mid term which I will be taking this evening. On the practice exam, the following question is given:
Given the following, which line is illegal, assuming that class Watch extends class Clock?
Clock A = new Clock();
Watch B = new Watch();
A=B;
B=A;
On the answer key, he states that B=A; is the illegal statement because a Clock is not necessarily a Watch...but that feels wrong....
User Profile
Collapse
-
Well in reverse2() you do want to keep the 0s, but we used the Math.pow() method to do it, I was just testing reverse3() as a replacement to reverse2(). =D There were supposed to be 2 methods in my program, one that takes out the 0s and reverses, and one that reverses and keeps the 0s. -
Thank all of you so much for the help. In my last post about reverse3() i meant to edit it to be recursive.
I tested it and this code does work. I went ahead and submitted the final version to the teacher along...Code:public static int reverse3(int a, int rev) { if (a < 10) return 10*rev+a; return reverse3(a/10, 10*rev+a%10); } }Leave a comment:
-
Also, let me know if you see something wrong with this? Instead of the original reverse2 method.
Code:public static int reverse3(int a, int rev) { if (a < 10) return 10*rev+a; return reverse1(a/10, 10*rev+a%10); } }Leave a comment:
-
Okay wow. I actually get it now. I added your code to my program, modified it so it could compile, then ran it in debug mode so I could see exactly how it worked. The problem I was having understanding it was the 2nd int parameter in the method. I feel like I tried everything except that. Also, it helped me learn how to use those ?:; statements, for some reason we didn't go over those in class. My final code:
...Code:Leave a comment:
-
-
And after reading your post again I got an idea, so I'm gonna try that right now.Leave a comment:
-
Jos, I would show you what I wrote if I had saved any changes to the code that I made Thursday night in Lab. I'm VERY new to this programming thing. I love it, but some concepts are still hard for me to grasp. Let me show you the actual assignment: http://www.midlandstech.edu/edu/ed/i...n/283/hw3.html
He extended the deadline, so I can work on it on Tuesday and Thursday during lab. The thing is...even my teacher can't...Leave a comment:
-
Thanks BSCode, I was still having problems getting reverse1() to work, and I think you just helped a lot.Leave a comment:
-
Thanks again Jos! When I get back from work I will try to do that. It seems simple enough :).Leave a comment:
-
Figured it out
Okay so I'm feeling really good about myself right now. I got the program to work fairly well. HOWEVER...dot dot dot...the reverse1() method is supposed to eliminate any zero's. For example, 1024 should become 421. But I cant think of a way to do this. Anyone have any ideas? I have until next Tuesday to figure it out.
...Code:import java.util.*; import java.lang.*; public class
Leave a comment:
-
Thanks Joe! It will take a while for me to fully comprehend what you just wrote, but I'm going to print it out and refer to it whilst I write the method. I have a good deal of freedom as far as writing the method goes so I dont see why I couldn't use two. As long as I'm not converting it to a string ha! Thanks again Joe. If anyone else has any more suggestions please post!Leave a comment:
-
Recursion...Its hard to grasp. Help.
So I have my Algorithms class tonight and I want to get the lab done before or during the class. I have write a recursive method that takes an int as a parameter and also returns an int. It has to REVERSE the int. What the heck. I'm not allowed to convert it to a string or anything, it says that I will not get credit if I do. So could someone give me some hints? The only thing I've gotten so far is the main method that accepts an int from the...
No activity results to display
Show More
Leave a comment: