{"id":"reading-input-string-variables","slug":"string-variables","title":"String variables","text":"A **variable** is a named place that holds a value. `String message = scanner.nextLine();` in the last step created one. Variables can also get their value straight from the code:\n\n```java\nString food = \"pizza\";\nSystem.out.println(food);\nSystem.out.println(\"food\");\n```\n\n```output\npizza\nfood\n```\n\nThe line `String food = \"pizza\";` has three parts:\n\n- `String` is the variable's **type**: what kind of value it holds. A `String` holds text.\n- `food` is the variable's **name**. You choose it.\n- `= \"pizza\"` gives it its value.\n\nAfter that, the name stands for the value. That's why `System.out.println(food)` prints `pizza`, while `System.out.println(\"food\")`, with quotes, prints the word `food` itself. Quotes mean \"this exact text\"; no quotes mean \"the value of this variable\".\n\nA variable has to be created before it's used, and Java checks the name's spelling and capitals: `Food` and `food` are two different names.\n","task":"Create a String variable called `planet` that holds the text `Mars`, and print the variable (not the text in quotes).\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        // Create the variable, then print it.\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        // Create the variable, then print it.\n        String planet = \"Mars\";\n        System.out.println(planet);\n    }\n}\n","hints":["A String variable is created like this: `String name = \"value\";`","Then `System.out.println(planet);` prints its value. No quotes around `planet`."],"tests":[{"name":"Output","stdin":"","expect":"Mars","hidden":false}],"require":[{"pattern":"String\\s+planet\\s*=","message":"Create the variable with `String planet = ...`."},{"pattern":"println\\s*\\(\\s*planet\\s*\\)","message":"Print the variable: `System.out.println(planet);`."}],"forbid":[],"more":[{"task":"This program should print the values of its two variables, but it prints their names instead. Fix it so it prints:\n\n```\nHelsinki\nFinland\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        String city = \"Helsinki\";\n        String country = \"Finland\";\n        System.out.println(\"city\");\n        System.out.println(\"country\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        String city = \"Helsinki\";\n        String country = \"Finland\";\n        System.out.println(city);\n        System.out.println(country);\n    }\n}\n","hints":["Text in quotes is printed exactly as written, so `\"city\"` prints the word city.","Remove the quotes around the names, so Java prints the variables' values."],"tests":[{"name":"Output","stdin":"","expect":"Helsinki\nFinland","hidden":false}],"require":[],"forbid":[{"pattern":"println\\s*\\(\\s*\"\"\\s*\\)","message":"Print the variables themselves, with no quotes around their names."}]},{"task":"Create three String variables: `breakfast` holding `oatmeal`, `lunch` holding `soup` and `dinner` holding `pasta`. Then print the variables in this order: dinner, breakfast, lunch.\n\n```\npasta\noatmeal\nsoup\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        // Three variables, then three prints.\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        // Three variables, then three prints.\n        String breakfast = \"oatmeal\";\n        String lunch = \"soup\";\n        String dinner = \"pasta\";\n        System.out.println(dinner);\n        System.out.println(breakfast);\n        System.out.println(lunch);\n    }\n}\n","hints":["One line per variable, for example `String lunch = \"soup\";`","The order of the prints decides the order of the output, not the order of the variables."],"tests":[{"name":"Output","stdin":"","expect":"pasta\noatmeal\nsoup","hidden":false}],"require":[{"pattern":"String\\s+breakfast\\s*=","message":"Create a variable called `breakfast`."},{"pattern":"String\\s+lunch\\s*=","message":"Create a variable called `lunch`."},{"pattern":"String\\s+dinner\\s*=","message":"Create a variable called `dinner`."}],"forbid":[{"pattern":"println\\s*\\(\\s*\"\"\\s*\\)","message":"Print the variables, not text in quotes."}]}]}