Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Code doesn't produce anything on screen - Doesn't give any erroreither while compiling / running.

Reply
Thread Tools

Code doesn't produce anything on screen - Doesn't give any erroreither while compiling / running.

 
 
Vasu
Guest
Posts: n/a
 
      10-18-2008
Hi Friends!

I have got the following code for converting Fahreignheit to Celsius,
which writes the output to a file called fout and then prints the
output from that file. It is compiled without producing any error,
and when I try to run it do not get any error also, but it doesn't
write anything on the screen either. When we take the output directly
from the code (without writing it on a file and reading from there)
it
works excellently, but when we take the first route the above is the
scene. Can somebody help tell me where is the problem and what is
the
solution if I want to read the results from a file. Here is the code
I'm using :

// Print a Fahrenheit to Celsius table

// Write the Fahrenheit to Celsius table in a file

import java.io.*;

class FahrToCelsius {

public static void main (String args[]) {

double fahr, celsius;
double lower, upper, step;

lower = 0.0; // lower limit of temperature table
upper = 300.0; // upper limit of temperature table
step = 20.0; // step size

fahr = lower;

try {

FileOutputStream fout = new FileOutputStream("test.out");

// now to the FileOutputStream into a PrintStream

PrintStream myOutput = new PrintStream(fout);

while (fahr <= upper) { // while loop begins here
celsius = 5 * (fahr-32) / 9;
myOutput.println((float)fahr+" "+(float)celsius);

fahr = fahr + step;
} // while loop ends here

} //try ends here

catch(IOException e){
System.out.println("Error: "+e);
System.exit(1);

}
} // main ends here
} //FahrToCelsius ends here

Thanks for your help and cooperation
Vasu
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      10-18-2008
Vasu wrote:
> Hi Friends!
>
> I have got the following code for converting Fahreignheit to Celsius,
> which writes the output to a file called fout and then prints the
> output from that file. It is compiled without producing any error,
> and when I try to run it do not get any error also, but it doesn't
> write anything on the screen either. When we take the output directly
> from the code (without writing it on a file and reading from there)
> it
> works excellently, but when we take the first route the above is the
> scene. Can somebody help tell me where is the problem and what is
> the
> solution if I want to read the results from a file. Here is the code
> I'm using :
>
> // Print a Fahrenheit to Celsius table
>
> // Write the Fahrenheit to Celsius table in a file
>
> import java.io.*;
>
> class FahrToCelsius {
>
> public static void main (String args[]) {
>
> double fahr, celsius;
> double lower, upper, step;
>
> lower = 0.0; // lower limit of temperature table
> upper = 300.0; // upper limit of temperature table
> step = 20.0; // step size
>
> fahr = lower;
>
> try {
>
> FileOutputStream fout = new FileOutputStream("test.out");
>
> // now to the FileOutputStream into a PrintStream
>
> PrintStream myOutput = new PrintStream(fout);
>
> while (fahr <= upper) { // while loop begins here
> celsius = 5 * (fahr-32) / 9;
> myOutput.println((float)fahr+" "+(float)celsius);
>
> fahr = fahr + step;
> } // while loop ends here
>
> } //try ends here
>
> catch(IOException e){
> System.out.println("Error: "+e);
> System.exit(1);
>
> }
> } // main ends here
> } //FahrToCelsius ends here
>
> Thanks for your help and cooperation
> Vasu


You could try closing the stream.

--

Knute Johnson
email s/nospam/knute2008/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      10-18-2008
Vasu wrote:
> Hi Friends!
>
> I have got the following code for converting Fahreignheit to Celsius,
> which writes the output to a file called fout and then prints the
> output from that file. It is compiled without producing any error,
> and when I try to run it do not get any error also, but it doesn't
> write anything on the screen either. When we take the output directly
> from the code (without writing it on a file and reading from there)
> it
> works excellently, but when we take the first route the above is the
> scene. Can somebody help tell me where is the problem and what is
> the
> solution if I want to read the results from a file. Here is the code
> I'm using :
>
> // Print a Fahrenheit to Celsius table
>
> // Write the Fahrenheit to Celsius table in a file
>
> import java.io.*;
>
> class FahrToCelsius {
>
> public static void main (String args[]) {
>
> double fahr, celsius;
> double lower, upper, step;
>
> lower = 0.0; // lower limit of temperature table
> upper = 300.0; // upper limit of temperature table
> step = 20.0; // step size
>
> fahr = lower;
>
> try {
>
> FileOutputStream fout = new FileOutputStream("test.out");
>
> // now to the FileOutputStream into a PrintStream
>
> PrintStream myOutput = new PrintStream(fout);
>
> while (fahr <= upper) { // while loop begins here
> celsius = 5 * (fahr-32) / 9;
> myOutput.println((float)fahr+" "+(float)celsius);
>
> fahr = fahr + step;
> } // while loop ends here
>
> } //try ends here
>
> catch(IOException e){
> System.out.println("Error: "+e);
> System.exit(1);
>
> }
> } // main ends here
> } //FahrToCelsius ends here
>
> Thanks for your help and cooperation
> Vasu


Kindly disregard my previous post.

To print to the screen, change fout to System.out in the PrintStream
constructor.

PrintStream myOutput = new PrintStream(System.out);

--

Knute Johnson
email s/nospam/knute2008/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gem install ruby-debug-ide errors don't give me anything to lookfor. Kedar Mhaswade Ruby 10 12-27-2010 01:01 PM
Do you think this code will produce any undefined behavior? Chris Thomasson C++ 10 11-17-2006 06:10 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
can java produce .exe? if it can produce jar,how do you do? aungkopyay@gmail.com Java 5 10-27-2006 02:07 AM
Give us 3 minutes; we give you the whole library lib Computer Support 0 01-27-2005 07:52 AM



Advertisments