1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Java

Connected

Exercise

Declare now, assign later

Sometimes you need to create a variable before you know what value it will hold. Java gives you this flexibility, which is particularly useful when the value depends on logic or calculations that come later in your code. Let's practice this pattern!

Instructions

100 XP
  • Declare a String variable called ingredients without assigning it any value.
  • Assign ingredients the value of "chocolate, eggs, milk, flour, sugar, vanilla".