comp 110 introduction to programming
play

COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 - PDF document

9/24/2015 COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 9/24/2015 Today


  1. 9/24/2015 COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 – 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? • COMP 110 ‐ Fall 2015 2 1

  2. 9/24/2015 Today Announcements • • Assignment 2 : Due Friday, Oct 2 @ 11:55 PM http://comp110.com/assignments/the‐worried‐wizard Polleverywhere • http://help.unc.edu/help/poll-everywhere-faq/ More For Loops • COMP 110 ‐ Fall 2015 3 Local Variables • Open Eclipse • New Java project etc.. You know the drill! public class test123 { public static void main(String[] args) { int num1 = 5; int count; for (count = 0; count <= num1; count++){ System. out.println(count); } } } COMP 110 ‐ Fall 2015 4 2

  3. 9/24/2015 Local Variables public class test123 { public static void main(String[] args) { int num1 = 5; int count; for (count = 0; count <= num1; count++) { int num2 = 10; System. out.println(count); System. out.println(num2); } } } COMP 110 ‐ Fall 2015 5 Local Variables public class test123 { public static void main(String[] args) { int num1 = 5; int count; for (count = 0; count <= num1; count++) { int num2 = 10; System. out.println(count); System. out.println(num2); } System. out.println(num2); } } COMP 110 ‐ Fall 2015 6 3

  4. 9/24/2015 String input import java.util.*; public class Example1 { public static void main(String[] args) { String str = "Yes"; int count = 0; Scanner keyboard = new Scanner(System.in); while (str.equalsIgnoreCase("Yes")){ System.out.println(count); count++; System.out.println("Would you like to continue?"); str = keyboard.next(); } } } COMP 110 ‐ Fall 2015 7 Debugger in Eclipse • Debugging allows you to run a program interactively while watching the source code and the variables during the execution • Using breakpoints in the source code, you specify where the execution of the program should stop • Add line numbers • Toggle breakpoint where needed https://www.youtube.com/watch?v=dHYM3b3ZEjU COMP 110 ‐ Fall 2015 8 4

  5. 9/24/2015 Debugger in Eclipse – exercise1 int count = 0; int number = 5; while ( count <= number) { System. out.println(count); count++; } COMP 110 ‐ Fall 2015 9 Debugger in Eclipse – exercise2 int num = 5; for ( int i = 0; i <= num; i++) { System. out.println(i); } COMP 110 ‐ Fall 2015 10 5

  6. 9/24/2015 Debugger in Eclipse – exercise3 int sum = 0; int numToSum = 0; Scanner keyboard = new Scanner(System. in); System. out.println("Please enter a number"); numToSum = keyboard.nextInt(); for( int i=0; i <= numToSum; i++){ sum += i; } System. out.println("The sum is " + sum ); keyboard.close(); COMP 110 ‐ Fall 2015 11 Next class More on loops • COMP 110 ‐ Fall 2015 12 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend