Tuesday 23 January 2018

Candy bar example in java

import java.io.*;
//import javax.swing.*;

class Candy {
  public static void main (String[] args) throws IOException {
   
    BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    int num1, num2, sum; // declares three integers
    double dollars; // declares a number that can have decimals
   
    System.out.print ("How many candy bars do you want  : ");
    System.out.flush();
   
    // read a line, and then converts it to an integer
    num1 = Integer.parseInt( stdin.readLine());
   
    System.out.print ("How many suckers you do want  : ");
    System.out.flush();
    num2 = Integer.parseInt( stdin.readLine());
   
    sum = num1 + num2; // Adds the two numbers;
    dollars = (double) sum * .75;
    System.out.println("You owe : $" + dollars);
    //JOptionPane.showMessageDialog(null,"You owe : $" + dollars);
  } // method main
}

0 comments: