mirror of
				https://github.com/Brandon-Rozek/website.git
				synced 2025-10-30 21:41:12 +00:00 
			
		
		
		
	Fixed old blog posts
This commit is contained in:
		
							parent
							
								
									2489aa163b
								
							
						
					
					
						commit
						4f2a4a063d
					
				
					 2 changed files with 28 additions and 159 deletions
				
			
		|  | @ -23,76 +23,15 @@ kind: | ||||||
| --- | --- | ||||||
| Sometimes you want to format your outputs. This is a quick cheatsheet containing the differerent escape sequences | Sometimes you want to format your outputs. This is a quick cheatsheet containing the differerent escape sequences | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | | Character    | Escape Sequence | | ||||||
|  | | ------------ | --------------- | | ||||||
|  | | Newline      | \n              | | ||||||
|  | | Tab          | \t              | | ||||||
|  | | Backspace    | \b              | | ||||||
|  | | Double Quote | \”        | | ||||||
|  | | Single Quote | \’        | | ||||||
|  | | Backslash    | \\              | | ||||||
|  | 
 | ||||||
|   |   | ||||||
| 
 |  | ||||||
| <table class="tg"> |  | ||||||
|   <tr> |  | ||||||
|     <th class="tg-yw4l"> |  | ||||||
|       Character |  | ||||||
|     </th> |  | ||||||
| 
 |  | ||||||
|     <th class="tg-yw4l"> |  | ||||||
|       Escape Sequence |  | ||||||
|     </th> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Newline |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \n |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Tab |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \t |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Backspace |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \b |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Double Quote            |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \” |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Single Quote |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \’ |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Backslash |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       \\ |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| </table> |  | ||||||
|  | @ -21,110 +21,40 @@ mf2_mp-syndicate-to: | ||||||
| kind: | kind: | ||||||
|   - note |   - note | ||||||
| --- | --- | ||||||
| To obtain console input for your program you can use the <code class="language-java">Scanner</code> class | To obtain console input for your program you can use the `Scanner` class | ||||||
| 
 | 
 | ||||||
| First import the relevant library | First import the relevant library | ||||||
| 
 | 
 | ||||||
| <pre class="language-java"><code class="language-java"> | ```java | ||||||
| import java.util.Scanner; | import java.util.Scanner; | ||||||
| </code></pre> | ``` | ||||||
| 
 | 
 | ||||||
| Then create a variable to hold the <code class="language-java">Scanner</code> object | Then create a variable to hold the `Scanner` object | ||||||
| 
 | 
 | ||||||
| <pre class="language-java"><code class="language-java"> | ```java | ||||||
| Scanner input; | Scanner input; | ||||||
| input = new Scanner(System.in); | input = new Scanner(System.in); | ||||||
| </code></pre> | ``` | ||||||
| 
 | 
 | ||||||
| Inside the parenthesis, the <code class="language-java">Scanner</code> binds to the System input which is by default the console | Inside the parenthesis, the `Scanner` binds to the System input which is by default the console | ||||||
| 
 | 
 | ||||||
| The new varible <code class="language-java">input</code> now has the ability to obtain input from the console. To do so, use any of the following methods | The new varible `input` now has the ability to obtain input from the console. To do so, use any of the following methods: | ||||||
| 
 | 
 | ||||||
| <table class="tg"> | | Method         | What it Returns                                            | | ||||||
|   <tr> | | -------------- | ---------------------------------------------------------- | | ||||||
|     <th class="tg-yw4l"> | | `next()`       | The next space separated string from the console           | | ||||||
|       Method | | `nextInt()`    | An integer if it exists from the console                   | | ||||||
|     </th> | | `nextDouble()` | A double if it exists from the console                     | | ||||||
|  | | `nextFloat()`  | A float if it exists from the console                      | | ||||||
|  | | `nextLine()`   | A string up to the next newline character from the console | | ||||||
|  | | `hasNext()`    | Returns true if there is another token                     | | ||||||
|  | | `close()`      | Unbinds the Scanner from the console                       | | ||||||
| 
 | 
 | ||||||
|     <th class="tg-yw4l"> |  | ||||||
|       What it Returns |  | ||||||
|     </th> |  | ||||||
|   </tr> |  | ||||||
| 
 | 
 | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       next() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       The next space seperated string from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       nextInt() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       An integer if it exists from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       nextDouble()              |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       A double if it exists from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       nextFloat() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       A float if it exists from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       nextLine() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       A string up to the next newline character from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       hasNext() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Returns true if there is another token |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| 
 |  | ||||||
|   <tr> |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       close() |  | ||||||
|     </td> |  | ||||||
|      |  | ||||||
|     <td class="tg-yw4l"> |  | ||||||
|       Unbinds the Scanner from the console |  | ||||||
|     </td> |  | ||||||
|   </tr> |  | ||||||
| </table> |  | ||||||
| 
 | 
 | ||||||
| Here is an example program where we get the user’s first name | Here is an example program where we get the user’s first name | ||||||
| 
 | 
 | ||||||
| <pre class="language-java"><code class="language-java"> | ```java | ||||||
| import java.util.Scanner; | import java.util.Scanner; | ||||||
| 
 | 
 | ||||||
| public class GetName { | public class GetName { | ||||||
|  | @ -135,4 +65,4 @@ public class GetName { | ||||||
|     System.out.println("Your first name is " + firstName);  |     System.out.println("Your first name is " + firstName);  | ||||||
|   } |   } | ||||||
| } | } | ||||||
| </code></pre> | ``` | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue