Introduction

Numbers, text, and true-or-false values behave differently. Adding numbers calculates a sum; combining strings joins text. Convert a value deliberately before using it in a calculation.

Syntax & example

public class Main {
  public static void main(String[] args) {
    int price = 12;
    int quantity = 3;
    System.out.println(price * quantity);
  }
}

Expected output

36

Common mistakes

  • Using a variable before assigning a value to it.
  • Mixing text and numbers without converting deliberately.
  • Skipping an empty input or a boundary value when testing.

Practice

Store a price and a quantity, then calculate their product.

13px
Main.javaYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-87 lines