Docsity

Exam with Solution - Introduction to Computing Java | CSC 116, Study notes of Java Programming

Toggle sidebar
bg1
๎˜๎˜‚๎˜๎˜ƒ๎˜„๎˜„๎˜…๎˜ƒ๎˜†๎˜ƒ๎˜‡๎˜‡๎˜ˆ๎˜ƒ๎˜‰๎˜Š๎˜‹๎˜Œ๎˜๎˜Ž๎˜๎˜๎˜ƒ๎˜๎˜‘๎˜’๎˜“๎˜Œ๎˜”๎˜๎˜’๎˜ƒ๎˜•๎˜–๎˜ƒ
๎˜ƒ
๎˜—๎˜Ž๎˜˜๎˜’๎˜™๎˜ƒ๎˜š๎˜š๎˜‚๎˜›๎˜๎˜œ๎˜๎˜”๎˜›๎˜Š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ๎˜ƒ๎˜ž๎˜Š๎˜”๎˜๎˜Ÿ๎˜ƒ๎˜‰ ๎˜™๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ!๎˜Ž"๎˜™๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜š๎˜ƒ
๎˜ƒ
๎˜„#๎˜ƒ๎˜ƒ$%๎˜Ž๎˜๎˜ƒ๎˜”๎˜๎˜ƒ๎˜%๎˜’๎˜ƒ&๎˜”''๎˜’๎˜“๎˜’๎˜Š๎˜Œ๎˜’๎˜ƒ"๎˜’๎˜(๎˜’๎˜’๎˜Š๎˜ƒ๎˜Ž๎˜ƒ(%๎˜”๎˜๎˜’๎˜ƒ๎˜๎˜›๎˜›)๎˜ƒ๎˜Ž๎˜Š&๎˜ƒ๎˜Ž๎˜ƒ&๎˜›๎˜‹(%๎˜”๎˜๎˜’๎˜ƒ๎˜๎˜›๎˜›)*๎˜ƒ
๎˜ƒ
๎˜๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜‚๎˜†๎˜ˆ๎˜ˆ๎˜‰๎˜‚๎˜Š๎˜„๎˜‡๎˜Š๎˜‹๎˜Œ๎˜‚๎˜๎˜„๎˜‡๎˜‚๎˜Ž๎˜ˆ๎˜ˆ๎˜†๎˜‡๎˜๎˜๎˜‚๎˜‡๎˜‘๎˜‰๎˜’๎˜‡๎˜Œ๎˜Œ๎˜…๎˜ˆ๎˜๎˜‚๎˜“๎˜‡๎˜”๎˜ˆ๎˜’๎˜‡๎˜‚๎˜‡๎˜‘๎˜‡๎˜Š๎˜•๎˜๎˜…๎˜๎˜–๎˜‚๎˜๎˜„๎˜‡๎˜‚๎˜†๎˜ˆ๎˜ˆ๎˜‰๎˜‚๎˜“๎˜ˆ๎˜—๎˜˜๎˜™๎˜‚๎˜‚
๎˜š๎˜„๎˜‡๎˜‚๎˜—๎˜ˆ๎˜›๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜‚๎˜†๎˜ˆ๎˜ˆ๎˜‰๎˜‚๎˜ƒ๎˜…๎˜†๎˜†๎˜‚๎˜‡๎˜‘๎˜‡๎˜Š๎˜•๎˜๎˜‡๎˜‚๎˜๎˜„๎˜‡๎˜‚๎˜†๎˜ˆ๎˜ˆ๎˜‰๎˜‚๎˜๎˜๎˜‚๎˜†๎˜‡๎˜๎˜Œ๎˜๎˜‚๎˜ˆ๎˜๎˜Š๎˜‡๎˜‚๎˜“๎˜‡๎˜”๎˜ˆ๎˜’๎˜‡๎˜‚๎˜Š๎˜„๎˜‡๎˜Š๎˜‹๎˜…๎˜๎˜–๎˜‚๎˜๎˜„๎˜‡๎˜‚
๎˜Š๎˜ˆ๎˜๎˜—๎˜…๎˜๎˜…๎˜ˆ๎˜๎˜™๎˜‚
๎˜ƒ
๎˜ƒ
๎˜ˆ#๎˜ƒ$๎˜“๎˜”๎˜๎˜’๎˜ƒ๎˜Ž๎˜ƒ'๎˜›๎˜“๎˜ƒ๎˜๎˜›๎˜›)๎˜ƒ๎˜%๎˜Ž๎˜๎˜ƒ๎˜Œ๎˜Ž๎˜๎˜Œ๎˜œ๎˜๎˜Ž๎˜๎˜’๎˜๎˜ƒ+,#๎˜ƒ๎˜ƒ-๎˜’๎˜˜๎˜’๎˜˜"๎˜’๎˜“๎˜ƒ๎˜%๎˜Ž๎˜๎˜ƒ๎˜‘,๎˜ƒ.๎˜ƒ/๎˜‘0/๎˜‘๎˜ƒ๎˜†๎˜ƒ๎˜„0/๎˜‘๎˜ƒ๎˜†๎˜ƒ๎˜ˆ0๎˜ƒ1๎˜ƒ/๎˜ˆ0/๎˜„0๎˜ƒ
๎˜ƒ
๎˜…๎˜๎˜๎˜‚๎˜”๎˜๎˜Š๎˜๎˜ˆ๎˜’๎˜…๎˜๎˜†๎˜‚๎˜œ๎˜‚๎˜๎˜ž๎˜‚๎˜‚๎˜Ÿ๎˜Ÿ๎˜๎˜‡๎˜‡๎˜—๎˜Œ๎˜‚๎˜๎˜ˆ๎˜‚๎˜“๎˜‡๎˜‚๎˜๎˜‚๎˜ˆ๎˜๎˜„๎˜‡๎˜’๎˜ƒ๎˜…๎˜Œ๎˜‡๎˜‚ ๎˜•๎˜†๎˜๎˜…๎˜‰๎˜†๎˜˜๎˜‚๎˜“๎˜˜๎˜‚!๎˜‚
๎˜”๎˜ˆ๎˜’"๎˜…๎˜๎˜๎˜‚๎˜…๎˜‚๎˜œ๎˜‚๎˜๎˜ž๎˜‚๎˜…๎˜‚#๎˜œ๎˜‚$๎˜ž๎˜‚๎˜…%%&๎˜‚'๎˜‚
๎˜‚ ๎˜”๎˜๎˜Š๎˜๎˜ˆ๎˜’๎˜…๎˜๎˜†๎˜‚(๎˜œ๎˜‚๎˜…๎˜ž๎˜‚
)๎˜‚
๎˜‚
๎˜…๎˜๎˜๎˜‚๎˜”๎˜๎˜Š๎˜๎˜ˆ๎˜’๎˜…๎˜๎˜†๎˜‚๎˜œ๎˜‚๎˜๎˜ž๎˜‚๎˜‚๎˜‚
๎˜”๎˜ˆ๎˜’"๎˜…๎˜๎˜๎˜‚๎˜…๎˜‚๎˜œ๎˜‚$๎˜ž๎˜‚๎˜…๎˜‚*๎˜œ๎˜‚๎˜๎˜ž๎˜‚๎˜…๎˜›๎˜›&๎˜‚'๎˜‚
๎˜‚ ๎˜”๎˜๎˜Š๎˜๎˜ˆ๎˜’๎˜…๎˜๎˜†๎˜‚(๎˜œ๎˜‚๎˜…๎˜ž๎˜‚
)๎˜‚
๎˜ƒ
๎˜๎˜‘๎˜๎˜“๎˜Ž๎˜ƒ๎˜๎˜“๎˜’&๎˜”๎˜๎˜™๎˜ƒ$%๎˜Ž๎˜๎˜ƒ๎˜”๎˜๎˜ƒ+,*๎˜ƒ+!,!๎˜ƒ
๎˜ƒ
๎˜ƒ ๎˜ƒ

Partial preview of the text

Download Exam with Solution - Introduction to Computing Java | CSC 116 and more Study notes Java Programming in PDF only on Docsity!

CSC 116 โ€” 002 In-class Exercise #3 Name: __ Solution Unity ID: Lab: 1. What is the difference between a while loop and a do-while loop? Awhile loop checks the Boolean expression before executing the loop body. The do-while loop will execute the loop at least once before checking the condition. 2. Write a for loop that calculates 7!. Remember that x! = (x)(x โ€” 1)(x โ€” 2) ... (2)(1) int factorial = 1; //needs to be 1 otherwise multiply by 0 for(int i = 1; i 7; itt) { factorial *= i; } int factorial = 1; for(int i =7; i 1; i-) { factorial *= i; } Extra Credit: What is 7!? 5040