Programming Exam
Programming Exam
hile Nested Arrays Strings Methods Classes Git Level1ExamSampleQuestions: 1. Writeastatementthatwilldeclareavariablewiththevalueofpi(upto3rddigit) 2. Inthefollowingcodesample,circleallsyntaxerrors: intx=0 intyz,r charc=w if(x=>10) { System.println(xislarge): } y+=x 3. Whichofthefollowingarevalidjavaidentifiers?(chooseallvalidones)
i. z=x+y b. Multiplyx,y,and3 c. Divideyby3timesx d. Theremainderofwand7 e. Subtractsfromq 5. Given: 1. intx=7,y=10,z=1 2. booleanfun=truesun=false Evaluatethefollowingexpressions: 1. x==7 2. 10!=y 3. x>y 4. y>=x+3 5. (x==y)||(fun) 6. !(sun&&fun)||(sun||fun) 7. (fun&&!(fun||sun)) 6. 7. Given 1. int[]a={1,2,3,4,5,6} 2. inti=a.length1 3. 4. while(i>=0){ 5. System.out.print(a[i]) 6. i 7. } What is the output?
8. Show the output from the snippet below
10. Give a single Java Statement (using System.out.println() )that outputs the following line: Bob said, Its C:\window 11. How do we compare strings? please provide code example
12. Writeacompletemethodwhichacceptsanarrayofintegersanddisplaysahistogrambasedonthose
numbers.Forexample,iftheuserenters2541theprogramwilldisplay: ** ***** **** *
13. what is short circuiting? 14. How often should you commit? How often should you merge to the master branch? 15. Why should you have more than one branch? 16. Construct an array that contains the first three prime numbers with one line; 17. Write a method that will return true if the parameter is even and false if the parameter is odd, if given int parameter, myinteger. 18. Construct a method that will return a string stating what day of the week it is given a parameter of an integer between 1 and 7 where 1 is monday and 7 is sunday. 19. Write a function that will find the maximum and minimum of an array of arbitrary size. 20. Write a Book class with the following constructor, methods and fields a. field i. private string bookName ii. private int ISBN iii. private boolean isBorrowed; b. Constructor i. Book() 1. Default bookName =; 2. Default ISBN = 0; 3. Default isBorroed = false; ii. Book(string name, int ISBN) 1. bookName = name; 2. ISBN = ISBN; c. Methods i. public int getISBN(); ii. public String getBookName(); iii. public String toString() 1. output format = bookname + + ISBN iv. public boolean isBorrowed() v. public void borrow()