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) ?
They've told outlets who got review units that it isn't. Partially because they believe that contributes to closed ecosystems. GamersNexus also believes this is because Valve's fighting a monopolistic practices lawsuit in Europe right now. They've also never subsidized any of their past hardware efforts and well, they definitely aren't subsidizing the Steam Deck right now.
(macOS) Screen zoom was broken for me in beta 1 and it's now working properly in beta 2. In terms of performance and UI design/consistency, these betas are already much better than Tahoe.
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 :
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) ?
Thanks for any help
Edited by Dr_AsikLink to comment
https://www.neowin.net/forum/topic/721948-algorithms-two-problems/Share on other sites
3 answers to this question
Recommended Posts