{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2.1.evenodd.gray

2.1.evenodd.gray - An Example Given an integer i write a...

This preview shows pages 1–3. Sign up to view the full content.

20 CSE 201 – Elementary Computer Programming 20 An Example Given an integer i , write a piece of code that outputs “even” or “odd” depending on whether the value of i is even or odd. CSE 201 – Elementary Computer Programming 21 An Example Given an integer i , write a piece of code that outputs “even” or “odd” depending on whether the value of i is even or odd. if ( ) { } else { } •A number must be either even or odd. They cannot be both. Because this is an ‘either-or’ situation, we use the if-else case.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
22 CSE 201 – Elementary Computer Programming 22 An Example Given an integer i , write a piece of code that outputs “even” or “odd” depending on whether the value of i is even or odd. if ((i % 2) == 0) { } else { } •Use the mod operator (%) on our integer variable, i , to find out if an number is evenly divisible by two. •If it is, then it’s an even number. CSE 201 – Elementary Computer Programming
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

2.1.evenodd.gray - An Example Given an integer i write a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online