•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,602 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1365 | Replies: 5 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Home Work Problem.
I understand what the program is suppose to do, but I do not understand how to implement it using Link List.
Please help me to understand the problem.
Write a program to perform ariththmetic with integers of unlimited size. You must read data from the input file, input.txt and send output to the file, output.txt.
Each data line has the following format:
number1 operator number 2, where the operator can be one of +, - or *. The operator is preceeded and followed by one or more spaces.
For + and -, Number1 and Number 2 are to be treated as large integers and each must be stored in a link list. Output the given expression and on the next line print the answer. For example,
22222233333333 + 4444455555 =
For *, Number1 is a large integer to be stored in a linked list. Number2 is a small integer whcih can be stored in an int variable. Output the given expression ans on the next line, print the answer for example,
23222222222222 * 7 =
223232323223333
the last line of data contains a zero.
Please help me to under the algorithm in solving this problem
I understand what the program is suppose to do, but I do not understand how to implement it using Link List.
Please help me to understand the problem.
Write a program to perform ariththmetic with integers of unlimited size. You must read data from the input file, input.txt and send output to the file, output.txt.
Each data line has the following format:
number1 operator number 2, where the operator can be one of +, - or *. The operator is preceeded and followed by one or more spaces.
For + and -, Number1 and Number 2 are to be treated as large integers and each must be stored in a link list. Output the given expression and on the next line print the answer. For example,
22222233333333 + 4444455555 =
For *, Number1 is a large integer to be stored in a linked list. Number2 is a small integer whcih can be stored in an int variable. Output the given expression ans on the next line, print the answer for example,
23222222222222 * 7 =
223232323223333
the last line of data contains a zero.
Please help me to under the algorithm in solving this problem
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 19
Solved Threads: 200
Although all you really need to do is look at his moniker to find out what he wants here.
"chetah" when sounded out is the current "slang" sound for cheater. The "street" sound for "er" is, now, almost always "ah".
"chetah" when sounded out is the current "slang" sound for cheater. The "street" sound for "er" is, now, almost always "ah".
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
Here is the code I have been working on, help with corrections
Class Node {
Int num;
Node next;
}
Public Class Number {
Public static void main (String [] args) {
Scanner in = new Scanner (new File Reader (“input.txt”)
PrinterWriter out = new PrintWriter (new FileWriter (“output.txt”)
Node top, last, np = null;
top = null;
// Load the input file into the link list
int n = in.nextInt()
While (n! =0) {
np = new node (num)
if (top = = null) {
top = np;
else {
last.next = np;
num = in.nextInt ()
}
}
Curr = top
While (curr !=Null)
String sign = in.next()
If (sign. equals (‘+’) {
Int sum = prev.next +curr.next
Curr = curr.next
//write to output file
Elseif{
If (sign. equals (‘-’) {
Int difference = prer.next -curr.next
Curr = curr.next
//write to output file
}
Else{
If (sign. equals (‘*’) {
Int product = curr.num *curr.next
Curr = curr.next
//write to output file
}
Class Node {
Int num;
Node next;
}
Public Class Number {
Public static void main (String [] args) {
Scanner in = new Scanner (new File Reader (“input.txt”)
PrinterWriter out = new PrintWriter (new FileWriter (“output.txt”)
Node top, last, np = null;
top = null;
// Load the input file into the link list
int n = in.nextInt()
While (n! =0) {
np = new node (num)
if (top = = null) {
top = np;
else {
last.next = np;
num = in.nextInt ()
}
}
Curr = top
While (curr !=Null)
String sign = in.next()
If (sign. equals (‘+’) {
Int sum = prev.next +curr.next
Curr = curr.next
//write to output file
Elseif{
If (sign. equals (‘-’) {
Int difference = prer.next -curr.next
Curr = curr.next
//write to output file
}
Else{
If (sign. equals (‘*’) {
Int product = curr.num *curr.next
Curr = curr.next
//write to output file
}
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- LinkedList Search (Java)
- Java 3D Environment (Java)
- Java 3D (Java)
- Java Expert (Needed) (Java)
- Java Chat Reboots (Java)
Other Threads in the Java Forum
- Previous Thread: How to get list ports in Linux
- Next Thread: print button



Linear Mode