1 / 12

CS 240 – Computer Programming I Lab

CS 240 – Computer Programming I Lab. Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/. Contact. Contact by e-mail kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm. Get input from key board.

beth
Download Presentation

CS 240 – Computer Programming I Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 240 – Computer Programming ILab KalpaGunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

  2. Contact • Contact by e-mail • 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 type name Create new object and assign to name

  4. Useful Arithmetic & Relational operators • > greater than, < less than, == equals to, != not equal to, >= 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 (<boolean expression> ) { runs if < boolean expression> is true } else { runs if < boolean expression> is false }

  6. If else if … if(< boolean expression>) { your code here } else if(< boolean expression>) { 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(“<rule>”, <number>) • 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

  9. Flow Chart • Condition • Statement input true false

  10. Example If then else

  11. Flow chart Pseudo code sum = 0  count = 1  REPEAT   IF count is even THEN sum = sum + count  count = count + 1  UNTIL count > 20  DISPLAY sum

  12. You can find useful information and helpful tips about flow charts at, • http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm

More Related