Professional Documents
Culture Documents
With Java”
Lecture – 5
nlp-ai@cse.iitb
Contents for Today’s Lecture
nlp-ai@cse.iitb
Recap
Structure of Java Program:
class class-name {
public static void main(String args[]) {
statements;
}
}
nlp-ai@cse.iitb
Recap…
Data Types:
Numbers – int (whole no.s), double (no.s with decimal point)
eg. int i = 23;
double d = 33.23
Character – char
eg. char c = ‘a’;
String – String
eg. String s = “Hi”;
Boolean – boolean
eg. boolean b = false;
Variable declaration:
data-type variable-name
eg. int i = 23;
nlp-ai@cse.iitb
Recap…
Expression:
An expression is a combination of literals (like 100), operators
(like +), variables and parentheses used to calculate a value.
eg. 2 + 6 / (2 – 9)
Operators:
Arithmetic –
eg. ‘-’, ‘+’, ‘/’, ‘++’ etc.
Relational –
eg. ‘<’, ‘>=’, ‘!=’ etc.
Conditional –
eg. ‘&&’ (AND), ‘||’ (OR)
Control constructs like‘if’ and ‘if else’:
nlp-ai@cse.iitb
Assignment
nlp-ai@cse.iitb
Solution
class synset {
public static void main(String args[]) {
int april = 12;
int may = 14;
int june = 8;
double avg;
avg = ( april + may + june ) / 3.0;
System.out.println("Synsets Entered for April " + april);
System.out.println("Synsets Entered for May " + may);
System.out.println("Synsets Entered for June " + june);
System.out.println("Average Synset Entered " + avg);
}
}
nlp-ai@cse.iitb
Assignment
nlp-ai@cse.iitb
Solution
class assign1 {
public static void main(String args[]) {
int a_number;
a_number = 5;
if(a_number == 1) System.out.println("One");
if(a_number == 2) System.out.println("Two");
if(a_number == 3) System.out.println("Three");
if(a_number == 4) System.out.println("Four");
if(a_number == 5) System.out.println("Five");
}
}
nlp-ai@cse.iitb
Arrays
Definition:
An array is a group/collection of variables of the same type
that are referred to by a common name and an index
Examples:
• Collection of numbers
• Collection of names
• Collection of suffixes
nlp-ai@cse.iitb
Examples
Array of numbers:
10 23 863 8 229
Array of names:
Array of suffixes:
nlp-ai@cse.iitb
Analogy
Array is like a pen box with fixed no. of slots of same size.
nlp-ai@cse.iitb
End
Thank you…
nlp-ai@cse.iitb