ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
A LIFO, either simulated ( eg, using two arrays ) or real ( eg, a stack ). This sounds too much like a homework exercise to offer you more than a hint.
can anyone help me with this... i'm currently doing this myself... (some code was given to me from the instructor to use in this program)
now, im stuck on the last loop, because the last loop makes num = null (because there is no more numbers), the program doesn't go on like it's supposed to. i've tried to make this into a pretested while loop, but i need to give a different value to "String oneLine = null", so it won't just exit right out of the loop. im not sure what value i can give to oneLine at the beginning for it to compile properly.
any ideas would be appriecated. thanks
String oneLine=null; /* the contents of a line of the user input file */
int numCount1=0;
do {
try {
oneLine = fileIn.readLine();
}
catch (IOException e) {
System.err.println("Sorry, unable to read a line from the file: " + filename);
System.exit(0);
}
int num = Integer.parseInt(oneLine); /* converts string to integer */
int revNum; /* holds the reversed digit */
int rightDigit=1; /* holds rightmost digit */
int numCount =-1; /* holds count of the while loop */
revNum = 0;
while (rightDigit !=0 ) {
rightDigit = num % 10;
revNum = revNum * 10 + rightDigit;
num = num / 10;
numCount = numCount + 1;
}
System.out.println("Read the line: " + oneLine);
System.out.println("Reversed is " + revNum / 10);
numCount1 = numCount1 + numCount;
System.out.println(numCount1);
} while (oneLine != null);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.