Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 06-27-2008, 06:20 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
janeansley, it's better that you familiar with basis error message handling in Java. All what you get in the code are simple ones.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 06-27-2008, 07:12 AM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Code:
import java.io.*; public class Testing { public static void main( String args[] ) throws java.io.IOException { final int PCOUNT = 5000; int a[]= new int[PCOUNT]; int i = 0; int j = 0; double y[]; String filename, inLine; //keyboard input stream InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); //get the input data System.out.print( "Enter the txt file name(full path): " ); filename = br.readLine(); //file input stream BufferedReader fi = new BufferedReader(new FileReader(filename)); //read existing data and calculate while((inLine = fi.readLine()) != null) { a[i] = Integer.parseInt(inLine); y[j] = ((4.2*a[i]/1010)-1.35); i++; } fi.close(); try{ FileWriter fw = new FileWriter("C:\\output.txt"); BufferedWriter out = new BufferedWriter(fw); String Temp = null; for(j=0; j<= i; j++){ Temp += y[j] + "\n";} out.write(Temp.substring(4)); out.close(); }catch (Exception A){} } }
After corected and compiled, another errors come again.
Quote:
Testing.java:32: variable y might not have been initialized
y[j] = ((4.2*a[i]/1010)-1.35);
^
Testing.java:42: variable y might not have been initialized
Temp += y[j] + "\n";}
^
2 errors
Why it said variable y might not have been initialized? I might did something wrong there. I am not sure whether my array has been declared properly. Please correct me thanks.
Bookmark Post in Technorati
Reply With Quote
  #23 (permalink)  
Old 06-27-2008, 07:17 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 899
Fubarable is on a distinguished road
It seems to me that your method of programming is:

1) find an error and post it here.
2) fix what is stated here, then go back to step one.

I think that somewhere in this loop you have to have:

3) try to debug it myself.

Don't you think?
Bookmark Post in Technorati
Reply With Quote
  #24 (permalink)  
Old 06-27-2008, 07:20 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Even get advice 100 times why these guys don't listen that. Try yourself at least a simple error like this. Error says that 'y' is not initialized. Go through the code and see is it true? If yes initialized it is.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #25 (permalink)  
Old 06-27-2008, 09:05 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
Eku is on a distinguished road
Yup you can figure that one. Try looking into the tutorials on declaration. Look for how to declare an array. ^_^
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #26 (permalink)  
Old 06-28-2008, 09:48 AM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Code:
import java.io.*; public class Testing { public static void main( String args[] ) throws java.io.IOException { final int PCOUNT = 5000; int a[]= new int[PCOUNT]; int i = 0; int j = 0; final double y[]= new double[PCOUNT]; String filename, inLine; //keyboard input stream InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); //get the input data System.out.print( "Enter the txt file name(full path): " ); filename = br.readLine(); //file input stream BufferedReader fi = new BufferedReader(new FileReader(filename)); //read existing data and calculate while((inLine = fi.readLine()) != null) { a[i] = Integer.parseInt(inLine); y[j] = ((4.2*a[i]/1010)-1.35); i++; } fi.close(); try{ FileWriter fw = new FileWriter("C:\\output.txt"); BufferedWriter out = new BufferedWriter(fw); String Temp = null; for(j=0; j<= i; j++){ Temp += y[j] + "\n";} out.write(Temp.substring(4)); out.close(); }catch (Exception A){} } }
Hi, I have initialized for the array and now the program can run finally and save into the output.txt file.
But the there's only a value save in the output.txt file in a row?
Please guide my problems. Thanks.

Quote:
5.0830693069306940.00.00.00.00.00.00.00.00.00.00.0 0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
Bookmark Post in Technorati
Reply With Quote
  #27 (permalink)  
Old 06-28-2008, 09:54 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You mean that, you want to write line by line, not in a same row? So write a new line in each case.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #28 (permalink)  
Old 06-28-2008, 01:49 PM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Yes, how to make the answer of the calculated value in the output.txt like this?

Quote:
3.764851485148515
3.848019801980198
5.249405940594061
6.891980198019802
3.9062376237623764
6.347227722772278
2.8583168316831684
4.9957425742574255
5.257722772277228
5.199504950495049
3.8812871287128714
3.8812871287128714
3.7814851485148515
5.257722772277228
6.463663366336634
6.833762376237624
5.490594059405941
4.796138613861386
4.326237623762376
5.087227722772278
3.83970297029703
4.796138613861386
3.8771287128712877
5.2909900990099015
5.083069306930694
Bookmark Post in Technorati
Reply With Quote
  #29 (permalink)  
Old 06-28-2008, 02:09 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Add the following line,

Code:
out.write(System.getProperty("line.separator"));
after the line,

Code:
out.write(Temp.substring(4));
in your code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #30 (permalink)  
Old 06-28-2008, 02:28 PM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Hi, Eranga. Still the same. I get this in the output.txt file after run.

Quote:
5.0830693069306940.00.00.00.00.00.00.00.00.00.00.0 0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
I wana make the calculated value to be save into the output.txt file,
Quote:
3.764851485148515
3.848019801980198
5.249405940594061
6.891980198019802
3.9062376237623764
6.347227722772278
2.8583168316831684
4.9957425742574255
5.257722772277228
5.199504950495049
3.8812871287128714
3.8812871287128714
3.7814851485148515
5.257722772277228
6.463663366336634
6.833762376237624
5.490594059405941
4.796138613861386
4.326237623762376
5.087227722772278
3.83970297029703
4.796138613861386
3.8771287128712877
5.2909900990099015
5.083069306930694

I have done some research on array, but cannot get it.
Please guide the problems. Thanks
Bookmark Post in Technorati
Reply With Quote
  #31 (permalink)  
Old 06-28-2008, 02:33 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Show me your new code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #32 (permalink)  
Old 06-28-2008, 02:49 PM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Code:
import java.io.*; public class Testing { public static void main( String args[] ) throws java.io.IOException { final int PCOUNT = 5000; int a[]= new int[PCOUNT]; int i = 0; int j = 0; final double y[]= new double[PCOUNT]; String filename, inLine; //keyboard input stream InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); //get the input data System.out.print( "Enter the txt file name(full path): " ); filename = br.readLine(); //file input stream BufferedReader fi = new BufferedReader(new FileReader(filename)); //read existing data and calculate while((inLine = fi.readLine()) != null) { a[i] = Integer.parseInt(inLine); y[j] = ((4.2*a[i]/1010)-1.35); i++; } fi.close(); try{ FileWriter fw = new FileWriter("C:\\output.txt"); BufferedWriter out = new BufferedWriter(fw); String Temp = null; for(j=0; j<= i; j++){ Temp += y[j] + "\n";} out.write(Temp.substring(4)); out.write(System.getProperty("line.separator")); out.close(); }catch (Exception A){} } }
I have added the code after that, but still the same at my C:\output.txt
which I get tis answers is not correct:
Quote:
5.0830693069306940.00.00.00.00.00.00.00.00.00.00.0 0.00.00.00.00.00.00.00.00.00.00.00.00.00.0
Bookmark Post in Technorati
Reply With Quote
  #33 (permalink)  
Old 06-29-2008, 07:06 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
First check that you logic is working fine or not. I can see in your code, only the first time do the calculation and after that nothing is changed. Actually the above output is not what you get, isn't it? You get a output stream with an annoying character like '[]', isn't it? Error is not with the new line print, it's an error with your application logic.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #34 (permalink)  
Old 06-30-2008, 04:48 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
Eku is on a distinguished road
hehehe i got your problem. I used \n for next line. if you used notepad to open the file you would see a straigth line. try using Wordpad ^_^ Wordpad can interpret text formatting such as \n. ^_^

Now for the zero output. There is just one wrong variable in the logic. you just have to look for it. Its a simple error ^_^ Try finding it ^_^

HINT: It is inside the while loop
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #35 (permalink)  
Old 06-30-2008, 05:54 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Eku View Post
HINT: It is inside the while loop
You got the point. Let see our friend can solve it out.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #36 (permalink)  
Old 07-04-2008, 08:50 AM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Hi, thanks Eku and Eranga. I got the right answers now.

The code part changed,
Code:
//read existing data and calculate while((inLine = fi.readLine()) != null) { a[i] = Integer.parseInt(inLine); y[j] = ((4.2*a[i]/1010)-1.35); i++; j++; }
I have one more problem is tat the calculated value is not in row by row.

All the output is in one very long row only.
Quote:
3.764851485148515
3.8480198019801985.2494059405940616.89198019801980 23.90623762376237646.3472277227722782.858316831683 16844.99574257425742555.2577227722772285.199504950 4950493.88128712871287143.88128712871287143.781485 14851485155.2577227722772286.4636633663366346.8337 623762376245.4905940594059414.7961386138613864.326 2376237623765.0872277227722783.839702970297034.796 1386138613863.87712871287128775.29099009900990155. 083069306930694
0.0
Can you guide me how to make them in row by row like this?
Quote:
3.764851485148515
3.848019801980198
5.249405940594061
6.891980198019802
3.9062376237623764
6.347227722772278
2.8583168316831684
4.9957425742574255
5.257722772277228
5.199504950495049
3.8812871287128714
3.8812871287128714
3.7814851485148515
5.257722772277228
6.463663366336634
6.833762376237624
5.490594059405941
4.796138613861386
4.326237623762376
5.087227722772278
3.83970297029703
4.796138613861386
3.8771287128712877
5.2909900990099015
5.083069306930694
Bookmark Post in Technorati
Reply With Quote
  #37 (permalink)  
Old 07-04-2008, 09:18 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Your data written part should be like this.

Code:
try{ FileWriter fw = new FileWriter("C:\\output.txt"); BufferedWriter out = new BufferedWriter(fw); for(j=0; j<= i; j++) { double Temp = 0; Temp += y[j]; String temp = Double.toString(Temp); out.write(temp); out.write(s); out.flush(); } out.close(); fw.close(); } catch (Exception A) { }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #38 (permalink)  
Old 07-04-2008, 09:32 AM
janeansley's Avatar
Member
 
Join Date: Jun 2008
Posts: 23
janeansley is on a distinguished road
Hi Eranga, I get this error.

Quote:
Testing.java:48: cannot find symbol
symbol : variable s
location: class Testing
out.write(s);
^
1 error
Where should I declare the variable "s"?
Bookmark Post in Technorati
Reply With Quote
  #39 (permalink)  
Old 07-04-2008, 09:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ah, that's the new line character I used. Replace it with following.

Code:
out.write("\n");
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 post