Thursday 15 April 2010

How do I save the output of my java program in another file even if it contains commands like for, if etc? -



How do I save the output of my java program in another file even if it contains commands like for, if etc? -

in code have printed patterns using , if statements. inquire how save pattern comes in output in text file can access later? here's code

import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; class eqns { double y,x,a,b,c; int u=0; bufferedreader br=new bufferedreader(new inputstreamreader(system.in)); void xyz()throws ioexception { string x1=joptionpane.showinputdialog(null,"the eqn of line ax + + c=0 come in value of a","graphs ©raghavgirgaonkar",joptionpane.plain_message); a=double.parsedouble(x1); string y1=joptionpane.showinputdialog(null," come in value of b","graphs ©raghavgirgaonkar",joptionpane.plain_message); b=double.parsedouble(y1); string z1=joptionpane.showinputdialog(null," come in value of c","graphs ©raghavgirgaonkar",joptionpane.plain_message); c=double.parsedouble(z1); joptionpane.showmessagedialog(null,"the eqn of line "+a+"x + "+b+"y + "+c+"=0","graphs ©raghavgirgaonkar comfirm",joptionpane.plain_message); system.out.println(" line: "+a+"x + "+b+"y = "+c); system.out.println(" ---the equation of line single grade equation---") ; for(y=20.0;y>=-20.0;y--) { for(x=-46.0;x<=46.0;x++) { if(a*x + b*y == c) { u=u+1; if(y==0&&x==0) continue; else if(x>0) system.out.print("۞ ("+x+","+y+")"); else if(x==0 || y==0) { system.out.print("۞"); continue; } else system.out.print("۞"); } else system.out.print(" "); if(y==0) { system.out.print("*"); } else if(x==0) { system.out.print("*"); } else system.out.print(" "); } system.out.println(); } if(0==(((0)*a + c)/b)) joptionpane.showmessagedialog(null,"this line passes through origin ","graphs ©raghavgirgaonkar",joptionpane.plain_message); if(u==0) joptionpane.showmessagedialog(null,"unfortunately line not satisfied intger co-ordinates hence line cannot printed ","graphs ©raghavgirgaonkar",joptionpane.plain_message); file f=new file("output.txt"); fileoutputstream fos=new fileoutputstream(f); printwriter pw=new printwriter(fos); pw.write(trial); pw.flush(); fos.close(); pw.close(); } void main()throws ioexception { eqns obj=new eqns(); obj.xyz(); } }

java

No comments:

Post a Comment