aspose file tools*
The moose likes Java in General and the fly likes Java operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java operator" Watch "Java operator" New topic
Author

Java operator

Kalpesh Jadhav
Greenhorn

Joined: Dec 26, 2011
Posts: 3
Hello I have assignment , could you please help me to solve this?

Write a program where in user enters 2 operand and a operator feed the same in file and read the file and display the Output result with all the operations in the end.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18138
    
  39

Kalpesh Jadhav wrote:Hello I have assignment , could you please help me to solve this?

Write a program where in user enters 2 operand and a operator feed the same in file and read the file and display the Output result with all the operations in the end.



Yeah, standard homework problem. It's actually a fun one in my opinion.

Anyway, tell us what you did so far, what issues your are running into (in as much details as possible), and we will give you some hints to help resolve those issues.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
And welcome to the Ranch

Are you using Java7?
Kalpesh Jadhav
Greenhorn

Joined: Dec 26, 2011
Posts: 3
Hi ,
I have take that all value in one file.
After that I have read that file one by one and do the operation on it.
I written code to write enter data to the file but I am not able to enter continuously the data in file .its just accepting one value only /
I have written this much code ,

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
I have added code tags, which usualy improves the look of your code, unfortunately is this case it highlights the inconsistent indentation. Are you supposed to have a loop in there? It is difficult to see, but I don’t think you do. That may be why you are only reading one value.
You shouldn’t need to flush System.out(). You have forgotten to close your reader.
By the way: don’t use tabs for indenting.
Kalpesh Jadhav
Greenhorn

Joined: Dec 26, 2011
Posts: 3
I have written this much by this code I am able to accept the values till user don't say "n".
And those value get updated in file also ,
Now my next task is todo operation. How to do this?

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

Kalpesh Jadhav wrote:I have written this much by this code I am able to accept the values till user don't say "n".
And those value get updated in file also ,
Now my next task is todo operation. How to do this?

Did you read Campbell's post? Because you are still flushing System.out and you still haven't closed your reader (and, probably more importantly, your writer).
Also, please UseCodeTags properly.

You also need to explain what you mean by "todo operation" (at least for me).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
You are mistaken that your loop (if you actually have a loop) continues until the user enters “n”. It actually runs as long as he enters something starting with y (not Y). I don’t think while(true) ... break; is good style. Have a look at this thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java operator
 
Similar Threads
Iterations - finding the same value for 2 variables
output redirect??
can any one explain this
Interview Question
JFileChooser save dialog without filename