Write a program that prompts the user to enter an integer


Multiple Choice and T/F Questions-

1. What is the output of the following statements? _______________

int x = 10;
x++;
int y = 11;
System.out.println(x);

A. 10
B. 11
C. y
D.x

2. 5 % 4 is _____

A. 0
B. 3
C. 4
D. 1

3. The equal comparison operator in Java is __________.

A. !==
B. ^=
C. <>
D. !=

4. To add a to b and store result in a, you write (Note: Java is case-sensitive)

A. b = A + b;
B. b += a;
C. a += b;
D. a = B + a;

5. Which of the following should be declared as a void method?

A. Write a method that converts an uppercase letter to lowercase.
B. Write a method that returns a random integer from 1 to 100.
C. Write a method that prints integers from 0 to 10.
D. Write a method that checks whether current second is an integer from 1 to 60.

6. Android apps are developed with Java.

True/False

7. Microsoft Visual Studio is the recommended integrated development environment for Android development, though developers may also use a text editor and command-line tools to create Android apps.

True/False

8. Layout files are stored in the project's res/menu folder.

True/False

9. A LinearLayout always arranges GUI components horizontally.

True/False

10. Android development is a combination of GUI design, Java, and XML coding.

True/False

Short Answer Questions-

11. Assume x is 80. What is the output of the following statement? Briefly explain your answer.

if (x >= 80){
System.out.print("A");
}
else if (x >=60){
System.out.print("B");
}
else{
System.out.print("C");
}

12. Write a program that prompts the user to enter an integer. If the number is a multiple of 3, print "Multiple of 3."Otherwise, print "Not Multiple of 3." Here are the sample runs:


Enter an integer: 6
Multiple of 3


Enter an integer: 10
Not Multiple of 3

13. What is the output for y?Briefly explain your answer.

int y = 0;
for (int i = 2; i <4; i++) {
y += i;
}
System.out.println(y);

14. What is the output of running the class C. Briefly explain your answer.

class A {
public String toString() {
return "AA";
}
}

class B extends A {
public String toString() {
return "BB";
}
}

public class C extends B{
public static void main(String[] args) {

A a = new A();
Bb = new B();
C c = new C();
System.out.println(a.toString()); // toString "A"
System.out.println(b.toString()); // toString "B"
System.out.println(c.toString()); // toString "B"
}
}

15. Change the following whilestatement using thefor statement.

int x = 1;
while (x <5){
System.out.println(x);
x++;
}

16. Complete the code:

public class Test {
public static void main(String[] args) {
int i = 4; int j = 5;

// Fill in the code to invoke the printAverage method to display the average of i and j.

}

public static void printAverage(int i, int j) {
// Fill in the code here to display the average of i and j.

}

}

17. How many times x will be printed? Briefly explain your answer.

int x = 1;
while (x <10){
System.out.println(x);
x++;
}

18. Create setter and getter for each member variable in the following class:

public class Stock {
private String stockName;
private double currentPrice;

// create a setter for "stockName"

// create a getter for "stockName"

// create a setter for "currentPrice"

// create a getter for "currentPrice"

}

19. Assume that you have the following xml file in your res/layout folder and the name of the xml file is activity_main.xml:

119_Code.png

(a) In order to display this user interface, what method call in Java will you use and how would you write that entire method call?

(b) How would the above layout xml file display on the screen?

20. Short Answer Questions (10 points)

(a) Suppose that "car_small.png" file is located in res/drawable folder.

- How can you refer to this file in Java code?

- How can you refer to this file in the layout XML file?

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a program that prompts the user to enter an integer
Reference No:- TGS01140858

Now Priced at $50 (50% Discount)

Recommended (96%)

Rated (4.8/5)