Download presentation
Presentation is loading. Please wait.
Published byMabel Goodwin Modified over 9 years ago
1
CS 240 – Computer Programming I Lab Kalpa Gunaratna – kalpa@knoesis.orgkalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/
2
Contact Contact by e-mail kalpa@knoesis.org kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm
3
Get input from key board Scanner keyboard = new Scanner(System.in); keyboard is the given name to the variable here. You can use any name you like. Object typenameCreate new object and assign to name
4
Useful Arithmetic & Relational operators > greater than, = greater than or equal to, <= less than or equal to, etc. Example: 5 > 6 will output false. Number 5 is not greater than 6. Boolean operators && - logical AND || - logical OR Example: x==5 && y<5, this expression outputs true if and only if value of x is 5 and value of y is less than 5.
5
If statements Syntax if ( ) { runs if is true } else { runs if is false }
6
If else if … if( ) { your code here } else if( ) { your code here } else { your code here }
7
Print statements System.out.print() Prints a line and stays in the current line Sytem.out.println() Prints a line and goes to a new line System.out.printf(“ ”, ) Ex: System.out.printf(“%.2f \n", 1234.123);
8
Pseudo Code Not a Java code or any programming language Human readable code similar to a programming language. Uses to describe algorithms. Example: Algorithm – if input value is greater than 5, out put to the console a success message. Otherwise exit program. Pseudo Code – Get user input value x. if x is greater than 5 then out put to console “Success” else exit from program You see that pseudo code has nothing to do with Java! More examples : http://www.unf.edu/~broggio/cop2221/2221pseu.htm http://www.unf.edu/~broggio/cop2221/2221pseu.htm
9
Flow Chart Condition Statement input true false
10
Example If then else
11
sum = 0 count = 1 REPEAT IF count is even THEN sum = sum + count count = count + 1 UNTIL count > 20 DISPLAY sum Pseudo code Flow chart
12
You can find useful information and helpful tips about flow charts at, http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.