Post on 18-Jan-2016
Condition & loop
Android Club 2015
Agenda
if/else• Switch• Loops
Condition: if
int month = 3;if (month == 3) {
System.out.println("March");}
Condition: if - practice
• Check if month August
Condition: else if
int month = 8;if (month == 4) {
System.out.println("March");} else if(month==8){
System.out.println("August");}
Condition: else if - practice
• Make conditional statement for all month – January - December
Condition: else
else {System.out.println("There is
not such month");}
Switch
int month= 3;
switch (month) {case 1:
System.out.println(“January");break;
case 2:System.out.println(“February");break;
default:System.out.println("This is no such month");
}
Switch: practice
• Create switch which shows day of week by its number
Switch: practice 2
• 400 – Bad Request• 401 – Unauthorized• 403 – Forbidden• 404 – Not found• 500 - Internal Server Error• Using switch show this errors
Loop: for
for (int i = 10; i < 20; i++) {System.out.println(i);
}
Loop: for - practice
• Print numbers from 100 till 900, inclusive
Loop: for – practice 2
• Find sum of numbers from 1 till 1000 inclusive
Loop: for – practice 3
• Using your month switch print all month
while
int x=0;while(x<10){
System.out.println(x);x++;
}
While - practice
• Print numbers from 1 till 1 000 000
While – practice 2
• Find sum of numbers from 1 to 333 inclusive
Let’s practice
•http://codingbat.com/
More practice!
• What can be better than practice? – More practice
•https://projecteuler.net
Questions?
• Any questions?
Review
• Lynda.com - Java Essential Training - 5. Exploring Syntax and Flow
Homework
• http://codingbat.com/java/Logic-1• Project Euler – 5 tasks
Thank you
• Thank you for your attention!