Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Lab2
Language: JAVA
Code:
import java.io.*;                 // needed for file work
import java.util.Scanner;         // needed for Scanner keyboard input

public class Lab2
{
   public static void main(String[] args) throws IOException
   {
   
      int number;
      
      // set up printer output file
      PrintWriter pw = new PrintWriter(new BufferedWriter
            (new FileWriter("output2.dat")));
            
      // Create a Scanner object to read keyboard input
      Scanner keyboard = new Scanner(System.in);   // reference p.84
      
      System.out.print("Enter a number: ");  // user prompt
      pw.print("Enter a number: ");          // sent prompt to printer file
      number = keyboard.nextInt ();          // get an inyeger from the keyboard
      pw.println(number);                  // send user input to printer file
      
      if(number >0)
      {
         System.out.println("The number you entered is positive");
         pw.println("The number you entered is positive");
      }
      else
      {
         System.out.println("The number you entered is negative or zero"); 
         pw.println("The number you entered is negative or zero");
      }
      
      pw.close(); // close printer output file
   }  // end of main () method
 } // end of class
Comments: