0
0
Javaprogramming~10 mins

Why variables are needed in Java - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an integer variable named 'age' with value 25.

Java
int [1] = 25;
Drag options to blanks, or click blank then click option'
A25
Bage
Cint
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value instead of the variable name.
Using a keyword instead of a name.
2fill in blank
medium

Complete the code to print the value of the variable 'score'.

Java
System.out.println([1]);
Drag options to blanks, or click blank then click option'
Ascore
B"score"
CSystem
Dprintln
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the variable name.
Using method names instead of variable.
3fill in blank
hard

Fix the error in the code by completing the variable declaration correctly.

Java
double [1] = 9.99;
Drag options to blanks, or click blank then click option'
Aprice
B9.99
Cdouble
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value as the variable name.
Repeating the type keyword.
4fill in blank
hard

Fill both blanks to declare a String variable 'name' and assign it the value "Alice".

Java
String [1] = [2];
Drag options to blanks, or click blank then click option'
Aname
B"Alice"
C"Bob"
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes for the text.
Using wrong variable names.
5fill in blank
hard

Fill all three blanks to declare an integer variable 'count', assign 10, and print it.

Java
int [1] = [2];
System.out.println([3]);
Drag options to blanks, or click blank then click option'
Acount
B10
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in declaration and print.
Not assigning a value.