2-Comments, Escape Sequence, Keywords, Scanner, Identifier, Variables-26-07-2022 (26-Jul-2022) Material - I - 26-07-2022 - 26.07.2022
2-Comments, Escape Sequence, Keywords, Scanner, Identifier, Variables-26-07-2022 (26-Jul-2022) Material - I - 26-07-2022 - 26.07.2022
26.07.2022
Comment Statements
• // This is a comment
• /* This is a
block comment */
Escape Sequence
• \n - New line
• \t - Horizontal tab
• \\ - Print backslash
Keywords
• Import package:
• Specific import
• import java.util.Scanner;
• Wildcard import
• import java.util.*;
• Example: GetInput.java
import java.util.Scanner;
public class GetInput
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a radius:");
double radius = input.nextDouble();
double area = radius * radius * 3.14;
System.out.println("Radius: "+radius+"Area:"+area);
}
}
Identifier
• Sequence of characters
• digits 0-9
• underscores _
• dollar sign $
• Starts with
• letter
• dollar sign
• underscore
Variables
• datatype varName;
• Initialization:
• Static: int a = 3;
• Dynamic:
• double c = Math.sqrt(a*a+b*b);