10th June 2015 - Scanner, Strings and Variables

Here is the cheat sheet provided at this weeks session:

Variable Names and Values:

VARIABLE SIZE Range DATA TYPE
byte 8 bits (a byte) -128 - +127 Whole numbers only
short 2 bytes -32,768 - +32,767 Whole numbers only
int 4 bytes -2,147,483,648 - +2,147,483,647 Whole numbers only
long 8 bytes -9,223,372,036,854,755,808 -
+9,223,372,036,854,755,808
Whole numbers only
float 4 bytes Floating point values, IEE Standard
754
Low precision decimal
point numbers
double 8 bytes Floating point values, IEE Standard
754
High precision decimal
point numbers
char 2 bytes If it's a keystroke or symbol on the
keyboard, it will store it
ONE single keystroke
or character at a time
boolean 1 byte True or False Underlying value stored
as 1 (True) or 0 (False)
string 2 bytes (per
character)
No limit (realistically) Collection of characters

Special Characters:

CODE SEQUENCE
DESCRIPTION
\b Inserts a backspace at this point in the text
\t Inserts a tab at this point in the text
\n Inserts a new line at this point in the text
\f Inserts a formfeed at this point in the text
\" Inserts double quotation marks at this point in the text
\' Inserts a single quotation mark at this point in the text
\\
Inserts a backslash at this point in the text

Reserved Words:

abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while

The Code for this week is as follows:

package HelloWorld;

import java.util.Scanner;

public class HelloWorld {

  public static void main(String[] args) {
  
    Scanner sc = new Scanner(System.in);
    System.out.println("What is your name");  
    String yourname = sc.next();
    String ysname = sc.next();
    System.out.println("Hello " + yourname + " " + ysname ); 
  
    sc.close();

  }

}