Answer:

Nothing. A file named output.txt in the current subdirectory will have its contents replaced with the output of the program. But files in other subdirectories are safe.

Discount Program

Here is a (slightly) more realistic program that computes the discounted price of an item, given the list price and the percentage discount:

import java.util.Scanner;
class Discount
{
  public static void main ( String[] args ) 
  {
    int listPrice;
    int discount;
    int discountPrice;

    Scanner scan = new Scanner( System.in );

    System.out.print("Enter list price in cents: ");
    listPrice = scan.nextInt();

    System.out.print("Enter discount in percent: ");
    discount = scan.nextInt();

    discountPrice = listPrice - (listPrice*discount)/100 ;

    System.out.println( "Discount Price: " + discountPrice );
  }
}

Here is an example of the normal operation of this program:

C:\users\default\JavaLessons>java Discount
Enter list price in cents: 100
Enter discount in percent: 10
Discount Price: 90

C:\users\default\JavaLessons>

QUESTION 11:

Can the output of this program be redirected to a file?