Wednesday, July 14, 2010

Introduction to Java Part 2 - Java

Output:
System.out.println (“text”);         //WORKS
System.out.println (“I want to print //WONT WORK
a really long message”); 
-The 2nd line won’t work, it will give an error, if your output goes to more than one line, change the code to the following:
System.out.println (“I want to print”) +
(“a really long message”);

Scanner Class:
-Makes input easy
-Imports special statements that are required for scanner class.
import java.util.*;
//or
import java.util.Scanner;
public class Hello
{
public static void main (String[] args)
{
Scanner in = new Scanner (System.in); //‘in’ can be changed, that is the name of the new Scanner.
int num;
double num2;
System.out.println (“Enter an integer”);
num = in.nextInt();
}
}
-This code takes the next integer typed into the keyboard and assigned it to the variable ‘num’
Escape Sequence:
-If I wanted to put a character like ‘ or “ the computer wont let me. What you have to do is put a \ then the character. \
char key = ‘\”’;
-The Variable ‘char’ would equal “
\n = New Line
\t = Tab


Debugging:
-Compile Errors (Gives error when compiling)
-Runtime Errors (Compiles fine but when you run it crashes)
-Logic Errors (Error in coding but computer doesn’t give an error)

0 comments:

Post a Comment