How to save output in a file

My proggy
import java.io.*;
public class temp
    public static void main (String [] args) throws Exception
        DataInput keyboard = new DataInputStream (System.in);
        int num = 0;
        String temp;
        String [] ques;
        String [] a, b, c, d, e;
        String [] ans;
        ques = new String [5];
        ques [0] = "(1) Which one of the following is an input device?";
        ques [1] = "(2) Which one of the following is an output device?";
        ques [2] = "(3)What does CPU stand for?";
        ques [3] = "(4)How many bytes in a megabyte";
        ques [4] = "(5)How many bytes in a gigabyte ?";
        a = new String [5];
        a [0] = "a) Printer";
        a [1] = "b) Monitor";
        a [2] = "c) Mouse";
        a [3] = "d) Speaker";
        b = new String [4];
        b [0] = "a) Mouse";
        b [1] = "b) Keyboard";
        b [2] = "c) Scanner";
        b [3] = "d) Speaker";
        c = new String [4];
        c [0] = "a) It does not stand for anything";
        c [1] = "b) Centeral Processing Unit";
        c [2] = "c) DUH!!!";
        c [3] = "d) City Power Unit";
        d = new String [4];
        d [0] = "a) 1";
        d [1] = "b) 1024";
        d [2] = "c) 4096";
        d [3] = "d) 1,048,576";
        e = new String [4];
        e [0] = "a) about 1 thousand";
        e [1] = "b) about 1 million";
        e [2] = "c) about 1 billion";
        e [3] = "d) about 1 trillion";
        ans = new String [5];
        ans [0] = "c";
        ans [1] = "d";
        ans [2] = "b";
        ans [3] = "d";
        ans [4] = "d";
        System.out.println ("\t\t\tWelcome to the quiz \n");
        System.out.println (ques [0] + "\n\n" + a [0] + "\n" + a [1] + "\n" + a [2] + "\n" + a [3]);
        System.out.print ("\nanswer : ");
        temp = keyboard.readLine ();
        if (temp.equals (ans [0]))
            System.out.println ("\n\nCorrect!!! \n");
            num = num + 1;
        else
            System.out.println ("\n\nWrong!!!\n\n");
        System.out.println (ques [1] + "\n\n" + b [0] + "\n" + b [1] + "\n" + b [2] + "\n" + b [3]);
        System.out.print ("\nanswer : ");
        temp = keyboard.readLine ();
        if (temp.equals (ans [1]))
            System.out.println ("\n\nCorrect!!! \n");
            num = num + 1;
        else
            System.out.println ("\n\nWrong!!!\n\n");
        System.out.println (ques [2] + "\n\n" + c [0] + "\n" + c [1] + "\n" + c [2] + "\n" + c [3]);
        System.out.print ("\nanswer : ");
        temp = keyboard.readLine ();
        if (temp.equals (ans [2]))
            System.out.println ("\n\nCorrect!!! \n");
            num = num + 1;
        else
            System.out.println ("\n\nWrong!!!\n\n");
        System.out.println (ques [3] + "\n\n" + d [0] + "\n" + d [1] + "\n" + d [2] + "\n" + d [3]);
        System.out.print ("\nanswer : ");
        temp = keyboard.readLine ();
        if (temp.equals (ans [3]))
            System.out.println ("\n\nCorrect!!! \n");
            num = num + 1;
        else
            System.out.println ("\n\nWrong!!!\n\n");
        System.out.println (ques [4] + "\n\n" + e [0] + "\n" + e [1] + "\n" + e [2] + "\n" + e [3]);
        System.out.print ("\nanswer : ");
        temp = keyboard.readLine ();
        if (temp.equals (ans [4]))
            System.out.println ("\n\nCorrect!!! \n");
            num = num + 1;
        else
            System.out.println ("\n\nWrong!!!\n\n");
          System.out.println ("--------------------------------------------------");
        System.out.println ("You answered " + num + " out of 5 questions correctly\n\n");
        if (num >= 5)
            System.out.println ("Grade A+ : You are Awesome\n\n ");
        else if ((num >= 4) && (num < 5))
            System.out.println ("Grade A : You did Great\n\n ");
        else if ((num >= 3) && (num < 4))
            System.out.println ("Grade C : You did Okay\n\n ");
        else
            System.out.println ("Grade F : You did Poorly\n\n ");
}is it possible to save all the output to a file, if yes then can you please tell me how
Thanks
Edited by: supahsain08 on Mar 3, 2008 3:09 PM

Class names should start with a capital.
Don't put all your code in the main method. Start to break it down into smaller chunks which can go into methods.
You need to read about File classes and IO. Do a search on the sun website for a tutorial.

Similar Messages

  • How to save a text or file in *doc from Pages?

    How to save a text or file in *doc?

    Igor,
    Use either File > Export, or Share > Export, and choose the Word option.
    Jerry

  • How to save downloaded update installer files

    How can I locate a downloaded update installer file so I can save it and use to install on another mac without having to download all over again?  Today I downloaded updates for OS X and also for Office 2011.  The first is over 2GB and the second around 300MB.  I have installed on my Macbook Pro, but I have another 3 units to update. I live in a 3rd world country with very slow internet and it takes me days to download such files.

    Grateful for you having replied but for some reason I seem unable to open your message "Re: How to save downloaded update installer files".  Waikato99

  • How to save output image after IMAQ-FFT to the file

    When I apply IMAQ FFT on monochromatic image and display complex destination image by IMAQ WindDraw, I get picture which I am not able to save to the file. I tried various conversions from complex image to bitmap (array), but result was everytime different from that got by IMAQ WindDraw.
    I thank for any help.

    Hallo Filip,
    you cannot save Complex Image to file to be readable by other programs - see link: http://digital.ni.com/public.nsf/websearch/D557B1A79C30AD5F86256AB1006A678A?OpenDocument
    What you can do is convert Complex Image to 8-bits BMP file format and save it then. This question was answered already - see example at: http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3ECED56A4E034080020E74861&p_node=DZ52000_US&p_source=External
    Hope this helps
    Pavel

  • Looking for Help on How To Save Video as Divx File

    Can someone help? I have iMoive 4.0.1 and I need to save video clips as a Divx file. I go to the "share" button and try to compress the clip for Quicktime and choose expert settings. This gives me a list of options including Divx AVI. When I choose this option, the file is turned into an .avi file not a .divx file. ANd there is no other Divx choice available. I have talked to another iMovie user (v4.0.1., too) and--the odd thing--on his option list he has Divx (not Divx AVI). So I need assistance in either finding another way to do this with my existing 4.0.1. or finding a plug-in that will allow me to save as a Divx file. Or--if no one can tell me how to do this--let me ask if anyone out there knows whether iMovie HD 5.0 or iMovie 6.0 would allow me to do what I need to do. Thanks.
    PowerBook G4   Mac OS X (10.3.9)  

    Divx isn't a standard option, so you have downloaded some third party support for Divx. Try the latest version.

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • "How Display and Output Acq'd File.VI works?"

    "My present project is somewhat similar to Display and Output Acq'd File.vi. But I don't clearly know how it works. My questions are:
    1. What will happen if the data-reading from file is faster than output-generation from buffered data?
    2. How does it match pace of reading and that of generation, and in which vi does the matching achieve?
    3. Is it possible to get these control information, like interrupt or DMA status in labview application?
    Thank you for your help
    Steven"

    I attached a bmp that illustrates how to read and write simultaneously from one file. The VI is using notifiers (under the advanced palette) to synchronize reader and writer loops.
    Note that the Wait function in the reader loop is irrelevant because the Wait on Notifier function blocks until data is available. This forces reader to be at least as slow as writer.
    Attachments:
    read_and_write.bmp ‏1014 KB

  • How to save pictures to a file outside of IPHOTO

    How you do you save photos to another file that isn't in Iphoto? I was trying to upload some photos to a webhosting site and I had the hardest time trying to find the library they were in. I ended up dragging the all to the desktop and renaming them.
    Is there an easier way to this? I did see the export feature..is that what I use and how do I do multiple photos?
    Thanks
    CC

    Not sure if this is what you're looking for but lets see if I cannot give you some idea.
    If you got to \User\yourname\Pictures\iPhoto Library\ Right click iPhoto Library and select Show Package Contents.
    In there, you will probably see 2 folders titled "Modified" and "Original"
    In those folders, you will see your pictures categorized into Years.
    Good luck. Hope thats what you were looking for.

  • How to save "sites" in separate files?

    I am working with three different sites (work, personal, etc.) and would like to save them as separate files, not as part of a single domain package. Is this possible without having to create separate user identities?
    Also, having saved two sites in iWeb, they are put in the domain.sites packages. Looking into the package I can’t distinguish which files belong to which sites. Any ideas,
    Cheers,
    Reb

    You could try this: create a site. Move the domain.site file to a folder named for the site. Start iWeb and create another site. Repeat. When you want to work on a specific site move its domain.site file into the iWeb application support file.
    Yep, a total pain in the neck. However it is either that or use a different user account for each site. My own experimentation has determined that as the total domain.site folder grows the save time grows tremendously.
    It's likely that before long someone will write a little utility to do this automatically.

  • Oracle script:How to avoid output in log file?

    Hi,
    I am try to create the xml file using some sql statements in a script.
    I dont want to display the output from these sql statements in log file.
    I tried with SET TERMOUT OFF, even then i am getting the output.

    I am getting the output even after using the SET echo off.
    I have given the following SET options,
         SET heading off
         SET feedback off
         SET verify off
         SET wrap off
         SET pagesize 0
         SET linesize 3000
    SET server off
         SET echo off
    I do not want to display the output in log file when i run the concurrent request.

  • How to save a Nikon NEF file as a Jpg

    When I go to FILE/SAVE AS I see a lot of file format options but no option for jpegs.  What am I missing?  I want to save a Nikon NEF file as a JPG.
    Don

    thank you SOOOO much - I was working fine - then all of the sudden the same thing - I must have touched some setting ! you guys ROCK!
    Carol in FL

  • How to save a Pages '09 file as Pages '08 in Mountain Lion?

    Help!  I upgraded to Mountain Lion and now with the Save As gone I can't save my Pages '09 files as Pages '08 files which I need to do very badly to share files with my teaching team.  Please help ASAP!!!!

    Save As… has returned with Mountain Lion. Hold down the Option/alt key while clicking on the File menu & there it is! It also has a default keyboard shortcut.

  • How generate a XML file & how to save data in that file?

    hi,
    How to generate an xml file & how to add data in that xml file? is there anyone who can help me about this? Firstly i need to open a xml file and after that i need to save user data in that file? how i will do it? What will be the solution of this? please give me solution........
    with regards
    Bina

    With an API like Xerces you can parse an XML document into a DOM tree. You can do modifications on that tree manually and then write it back out as XML data.
    http://xerces.apache.org/xerces2-j/

  • How to save adobe Premiere CS6 files in CS5.5?

    I have Adobe Premiere CS6 installed in my PC but my college Adobe version is cs5.5..so how can i save CS6 files into CS5.5?? i have checked a few forums but couldnt find a solution!!

    http://translate.google.ru/translate?sl=ru&tl=en&js=n&prev=_t&hl=ru&ie=UTF-8&eotf=1&u=http %3A%2F%2Fwww.efxi.ru%2Fmore%2Fpremiere_pro_cs6_open_project.html

  • How to save string in a file with special-chars

    Hello,
    i´m usingthe MD5-llb to create a password.
    Then i  want to save this MD5-string to a file and later read it back abd compare.
    Works perfect with one proplem:
    Some word create a "\r" in the MD5-string and when i save this string to a file and read it back then its read back as a "\n" so that the compare is not working.
    My question is: How can i save a string exactly like it is to somewhere and read it back (also invisible chars)
    For example the word: heinz
    is in MD5: \r\FB^\07\A6\07T\C7\D9\C2\94\AB\C9\1DS\95 (string indicator as codes display)
    when i save the string to a file then i rerad back: \n\FB^\07\A6\07T\C7\D9\C2\94\AB\C9\1DS\95
    I used the "write text file" and "read text file"
    What do i have to use to save and read the same?
    Thx
    Solved!
    Go to Solution.

    I believe an MD5 hash is 16 bytes long. Use the binary read and write file I/O functions and specify the length of the data to be read or written.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

Maybe you are looking for

  • How to change font-size of application menu

    I want to change font-size of application menu. How?

  • Multiple page PDF's for iTunes playlists

    In the past I've been able to create multiple page PDF's of playlists, but for some reason in iTunes 10.1 it will only show me the first page. At the bottom of that page it'll say page 1 of 10, but the other 9 pages do not appear in the sidebar. I al

  • HashSet get() and contains() methods, by value or reference?

    All the tutorials I've seen on HashSets use Strings as the object type. With Strings, it seems the get() and contains() methods work by value, not by reference. <CODE> String s1 = "dog"; String s2 = "cat"; String s3 = "dog"; HashSet<String> set = new

  • How to set Max Inactive Interval on ProviderSession

    I see a getMaxInactiveInterval in the api for provider session that says you can call setMaxInactiveInterval but I don't see it. Am I missing something? Do I need to call another method to set the max time interval?

  • Apple Mac Pro online work PDF damage, cant recongnize file??

    Hi Everyone, I recently brought a Apple Mac Pro for work, i do a lot of documentation online, i can't seem to open any documents to edit, i tried downloading Adobe Reader, I have been constantly searching for solutions and i'm pulling my hair out. i'