Hello, I am reading Mark Allen Weiss' Data Structures and Algorithm Analysis in Java, 2nd edition, and I can't seem to be able to resolve the most simple problems. This is the manual for my course on algorithms, but the problems aren't assignements per say.
Problem 1.3 :
Write a method to output an arbitrary double number (which might be negative) using only printDigit for I/O.
printDigit is not in the Java standard, it's defined a few pages before as "will take a single-digit number and output it to the terminal", but I have to implement it myself.
So in other words, I have to output an arbitrary double one digit at a time, in decimal representation. Now, with a positive integer I can just do :
public class Exercice3 {
public static void main(String[] args) {
printOut(1329);
}
// Recursive method that prints a positive integer one character at a time
public static void printOut(int n) {
if (n>= 10) {
printOut(n / 10);
}
printDigit(n % 10);
}
public static void printDigit(int n) {
if (0 <= n && n <= 9) {
System.out.print(n);
}
}
}
However, for the double, what should be the base case, in other words : where does the recursion stop ? The number can have any number of decimals after 0.
***********************
Problem 1.4 :
C allows statement of the form
#include filename
which reads filename and inserts its contents in place of the include statement. Include statements may be nested; in other words, the file filename may itself contain an include statement, but, obviously, a file can't include itself in any chain. Write a program that reads in a file and outputs the file as modified by the include statements.
I simply don't understand the question. How can include statements modify a file that I am able to output within the program ? Should the program be written in C (wtf, it's a Java book) ?
Question
Andre S. Veteran
Hello, I am reading Mark Allen Weiss' Data Structures and Algorithm Analysis in Java, 2nd edition, and I can't seem to be able to resolve the most simple problems. This is the manual for my course on algorithms, but the problems aren't assignements per say.
Problem 1.3 :
Write a method to output an arbitrary double number (which might be negative) using only printDigit for I/O.
printDigit is not in the Java standard, it's defined a few pages before as "will take a single-digit number and output it to the terminal", but I have to implement it myself.
So in other words, I have to output an arbitrary double one digit at a time, in decimal representation. Now, with a positive integer I can just do :
However, for the double, what should be the base case, in other words : where does the recursion stop ? The number can have any number of decimals after 0.
***********************
Problem 1.4 :
C allows statement of the form
#include filename
which reads filename and inserts its contents in place of the include statement. Include statements may be nested; in other words, the file filename may itself contain an include statement, but, obviously, a file can't include itself in any chain. Write a program that reads in a file and outputs the file as modified by the include statements.
I simply don't understand the question. How can include statements modify a file that I am able to output within the program ? Should the program be written in C (wtf, it's a Java book) ?
Thanks for any help
Edited by Dr_AsikLink to comment
Share on other sites
3 answers to this question
Recommended Posts