# Sample Code ## Escape Characters <table border="2" rules="groups" cellspacing="0" cellpadding="6"><colgroup><col class="org-left"> <col class="org-left"></colgroup><tbody><tr><td class="org-left">Escape Sequence</td><td class="org-left">Character</td></tr><tr><td class="org-left">\n</td><td class="org-left">newline</td></tr><tr><td class="org-left">\t</td><td class="org-left">tab</td></tr><tr><td class="org-left">\b</td><td class="org-left">backspace</td></tr><tr><td class="org-left">\"</td><td class="org-left">double quote</td></tr><tr><td class="org-left">\'</td><td class="org-left">single quote</td></tr><tr><td class="org-left">\\</td><td class="org-left">backslash</td></tr><tr><td class="org-left">\uDDDD</td><td class="org-left">Unicode character</td></tr></tbody></table> ```java public class uni { public static void main (String args \[\]) { System.out.println("\\u0041"); } } ``` ## Simple Scanner ```java import java.util.Scanner; public class Simpscan { public static void main (String args \[\]) { System.out.println("Enter your name"); Scanner scan = new Scanner(System.in); String s = scan.next(); System.out.println("Hello " + s); } } ``` ## System.out.format ```java double pi = 3.1415; System.out.format("Pi is %f to 4 d.p.%n", pi); #+RESULTS Pi is 3.141500 to 4 d.p. ``` # Exercise 1. Use the \\t escape character to print out a noughts and crosses grid, as shown below in fig. 1 2. Prompt the user to enter their (name). Print out "Hello" (name) "I hope you're well" 3. Use Math.sqrt() to print out the square root of 20 4. Use Math.sqrt() to print out the square root of 20 to 2 decimal places 5. Use Math.random() to print out a random integer between 5 and 10 6. Use Math.pow() to print out 2 to the power of 8 7. Prompt the user to enter a (number). Print out "The square root of " (number) " is " (answer) 8. Prompt the user to enter two numbers. Print out the average of those numbers. 9. To work out your BMI, divide your weight in kilograms by your height in metres squared. In other words BMI = w / h\*h. Write a program that prompts the user to input their weight and height, and then outputs their BMI. <table border="2" rules="groups" cellspacing="0" cellpadding="6"><caption class="t-above"><span class="table-number">Table 1:</span> fig. 1</caption><colgroup> <col class="org-left"> <col class="org-left"> <col class="org-left"></colgroup><tbody><tr><td class="org-left">o</td><td class="org-left"></td><td class="org-left">x</td></tr><tr><td class="org-left"></td><td class="org-left">x</td><td class="org-left">o</td></tr><tr><td class="org-left">o</td><td class="org-left">x</td><td class="org-left">o</td></tr></tbody></table>