CS 251 Intermediate Programming Prof. Patrick Gage Kelley - - PowerPoint PPT Presentation

cs 251 intermediate programming
SMART_READER_LITE
LIVE PREVIEW

CS 251 Intermediate Programming Prof. Patrick Gage Kelley - - PowerPoint PPT Presentation

CS 251 Intermediate Programming Prof. Patrick Gage Kelley University of New Mexico Reminders Get a CS account (at FEC 307 from George) Labs start on Tuesday Section 1: T 12:00-12:50 SMLC B59 Matthew Section 2: T 15:00-15:50


slide-1
SLIDE 1

CS 251 Intermediate Programming

  • Prof. Patrick Gage Kelley

University of New Mexico

slide-2
SLIDE 2

August 24, 2012, 251-3

Reminders

  • Get a CS account (at FEC 307 from George)
  • Labs start on Tuesday

Section 1: T 12:00-12:50 —SMLC B59 — Matthew Section 2: T 15:00-15:50 —ESCP 110 — Jan Section 3: T 11:00-11:50 —ESCP 110 —Matthew

  • Next week live programming!
  • Monday, will go over updated calendar
  • First programming project will be out in early

September

slide-3
SLIDE 3

August 24, 2012, 251-3

  • Write a line of code that prints out:

This is Answer 1.

slide-4
SLIDE 4

August 24, 2012, 251-3

  • Write a line of code that prints out:

This is Answer 1.

System.out.println(“This is Answer 1.”);

slide-5
SLIDE 5

August 24, 2012, 251-3

  • Write a method notThis that takes some text and

returns that text with “not ” added to the front. If it already starts with “not” just return it.

slide-6
SLIDE 6

August 24, 2012, 251-3

  • Write a method notThis that takes some text and

returns that text with “not ” added to the front. If it already starts with “not” just return it. String notThis( String s ) { if( s.indexOf( "not " ) == 0 ) { return s; } else { return "not " + s; } }

slide-7
SLIDE 7

August 24, 2012, 251-3

  • Write a method addUpThePositives that adds up

all of the positive integers in an array that is passed into it and returns the sum.

slide-8
SLIDE 8

August 24, 2012, 251-3

  • Write a method addUpThePositives that adds up

all of the positive integers in an array that is passed into it and returns the sum.

int addUpThePositives( int [] numbersToAdd ) { int sum = 0; for( int i=0; i<numbersToAdd.length; i++ ) { if( numbersToAdd[i] > 0 ) { sum += numbersToAdd[i]; } } return sum; }

slide-9
SLIDE 9

August 24, 2012, 251-3

  • Write a method isMultipleOfTwo that takes an

integer n as an argument, and that returns true if n is a multiple of two, and otherwise false.

slide-10
SLIDE 10

August 24, 2012, 251-3

  • Write a method isMultipleOfTwo that takes an

integer n as an argument, and that returns true if n is a multiple of two, and otherwise false. boolean isMultipleOfTwo( int n ) { boolean isIt = false; if( n % 2 == 0 ) isIt = true; return isIt; }

slide-11
SLIDE 11

August 24, 2012, 251-3

public int lotteryTicket(int a, int b, int c) { ! int worth = 0; ! if( a == b || b == c || c == a ) worth = 10; ! if( a == b && b == c ) worth = 20; ! return worth; }

slide-12
SLIDE 12

August 24, 2012, 251-3

  • What will be the output of the following statement?

for (int i=0; i<1; System.out.println(""+2+i+++i+++i));

slide-13
SLIDE 13

August 24, 2012, 251-3

  • What will be the output of the following statement?

for (int i=0; i<1; System.out.println("" + 2 + i + ++i + ++i));