vendredi 30 septembre 2016

Java IF Statement

I'm trying to write a Java program with a bunch of IF Statements. I'm confused about what it's actually supposed to look like. Could someone pleaaaase please give me an example with the question below, or something similar? Do IF Statements require a System.out.print for every variable in order for it to compile?

// Thank you soooo much!!!

Use a nested if to test the following conditions: If a boolean variable called sale is set to true, do the following: If the int variable price is less than 50, the double variable discount is set to 0.01. If the int variable price is 50 or greater, the double variable discount is set to 0.02.

This is the code I wrote for this, but I don't think it's correct....

boolean sale;
 int price;
 double discount;

 System.out.print("Please Enter Sale ");
  sale = keyboard.nextBoolean();

  if (sale == true)
    if  (price <= 50)
    discount = 0.01;

    else (price >= 50)
    discount = 0.02;

Aucun commentaire:

Enregistrer un commentaire