Slides0116

Slides0116 - COP 3330 Slides 1/16 Topics Comments, style,...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Slides 1/16 COP 3330
Background image of page 1

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

View Full DocumentRight Arrow Icon
Topics Comments, style, and whitespace Type Conversion Literals
Background image of page 2
Example Write a program that takes in an integer input from the user and determines if the input is prime or composite. - Recall that an integer is prime iff it is greater than 1 and it is divisible only by itself and 1 - Recall that an integer is composite iff it is greater than 1 and it is not prime
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example Write a program that implements a guessing game. (Where you tell the user if their guess was too high or low after each turn.) - To make the game more fun, it’s best have the program generate a random number - Math.random() gives a pseudo-random double between 0 and 1
Background image of page 4
Example Write a program that reads in a string and counts how many 'a's are in the string. - Strings in Java are objects, not char arrays - The length() method gives the length of the string - The charAt(int) method gives the char at the specified location
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example Write a program that allows the user to play rock, paper, scissors against the computer up to a score of 10
Background image of page 6
Comments Comments are ignored by the compiler Line comments - // This is a line comment Block comments - /* This is a block comment */
Background image of page 7

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

View Full DocumentRight Arrow Icon
Comments Why comment? - For others - For yourself When to comment? - Before a class definition Describe the purpose of the class and important things to know about it
Background image of page 8
Comments When to comment? - Before a method definition Describe the purpose of the method, the meaning of the formal parameters, and the meaning of the return value - Before variable declarations Describe the purpose of your variables - Mixed in with code Explain what your code is doing and why
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

Slides0116 - COP 3330 Slides 1/16 Topics Comments, style,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online