Week 2
Week 2
Lecture-1
Lecture-2
Lecture-3
Week-2
Week-2
Week-2
Lecture-4
final float pi = 3.1415927f;
Lecture-5
Operators
Week-2
Lecture-4
When both arguments are integer, / is integer division
Lecture-5 No exponentiation operater, use Math.pow()
Math.pow(a,n) returns an
Special operators for incrementing and decrementing integers
int a = 0, b = 10;
a++; // Same as a = a+1
b--; // Same as b = b-1
Shortcut for updating a variable
int a = 0, b = 10;
a += 7; // Same as a = a+7
Strings
Week-2
Lecture-4
+ is overloaded for string concatenation
Lecture-5 String s = "Hello";
String t = "world";
String u = s + " " + t;
// "Hello world"
Strings are not arrays of characters
Instead use s.charAt(0), s.substring(0,3)
Arrays
Week-2
Week-2
Conditional execution
Lecture-1 if (condition) { ... } else { ... }
Lecture-2
Conditional loops
Lecture-3
Lecture-4
while (condition) { ... }
Lecture-5 do { ... } while (condition)
Iteration - Two kinds of for
Multiway branching – switch
Classes and objects
Week-2
Week-2
Week-2
Week-2
Reading input
Lecture-1
Use Console class
Lecture-2
Use Scanner class
Lecture-3 Scanner in = new Scanner(System.in);
Lecture-4 String name = in.nextLine();
Lecture-5
int age = in.nextInt();