java 1-7 (code)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What will the following code print to the console? for(int a = 0; a <= 10; a++) { System.out.println("\"Blessings to You!\""); }

"Blessings to You!" eleven times

Given char ch; int num = 5; double pay; Which of the following assignment statements are valid? (i) ch = '*'; (ii) pay = num * 12.50; (iii) pay = rate * 40;

(i) and (ii) are valid

What is the output of the following code above? int x = 3, y=20,z=1; if(z<x) { System.out.println ("**"); } else if (y>x) { System.out.println("***"); } else System.out.println("*");

**

public int mystery(int x, int y){ if (x >= y) return x - y; else return x + y; } Based on the above code, what would be the output of the statementSystem.out.println(mystery(8,7));

1

The value of the expression 14 % 3 is ____.

2

String sentence; String str1, str2, str3; int length1; sentence = "First exam is on Monday."; str1 = sentence.substring(6, 12); str2 = str1.substring(0, 4); str3 = sentence.replace('i', '#'); length1 = sentence.length(); Based on the code above, what is the value of length1?

24

Suppose that x = 8 and y = 2. What is the output of the following Java statement?System.out.println(x + " and " + y + " is "+ (x + y));

8 and 2 is 10

Consider the following statements.double x = 85.6791;What does the following statement output? System.out.printf("%.2f", x);

85.68

What does the following code output? for (int a = 0; a < 3; a++) ; { System.out.println("Be Great Today!!") ; }

Be Great Today!! once.

What will the following statement output? System.out.println("Hello " + 2 + 0 + 1 + 9 + "!");

Hello 2019!

Consider the following program. public class HelloWorld { public static void main(String args) {System.print("Hello World ")}What will the program output?

None of these. There are errors.

charAt(2) is a String method that will _________________.

Return the third character in the string

Consider the following sequence of statements. String str; int num1, num2; num1 = 18; num2 = 30; str = "The sum = " + num1 + num2; What is the final value stored in str?

The sum = 1830

Based on the following code, select the correct method call to execute the method: public static void calculateAvg (int a, int b, double tax) { System.out.println(a * b); }

calculateAvg(5, 10, 3.25);

Determine whether the statement x < d && d < x is true or false based on the following int x = 55; int d = 35;

false

If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a is 3.

false

The following code returns a boolean: public static void Healthy (boolean t, String name) { System.out.println("I am healthy"); t = true; return t; }

false

Consider the following program. public class CircleArea{ static Scanner console = new Scanner(System.in); static final float PI = 3.14; public static void main(String[]args){ float r; float area; r = console.nextDouble(); area = PI * r * r; System.out.println("Area = " + area); } } To successfully compile this program, which of the following import statement is required?

import java.util.*;

Consider the following code, how many times will the loop iterate? int a = 10; int b = 0; int c = -1; while(c >= a) { System.out.println (a + " " + b + " " + c); c = c + 5; b++; }

none

Consider the following code, how many times will the loop iterate and print to the console? int a = 25; do { System.out.println(a); a++; } while (a <= 25);

once

When creating a method that returns a value, what must change in the following method header? public static void printAverage (int a, int b) { }

return type

what would the following statement print? System.out.println( "sum is " + 12 + 26 );

sum is 1226

If a = 4; and b = 3;,then after the statement a = b; executes, the value of b is 3 and the value of a is 3.

true

In Java, the result of the expression 28.0 / 7 is 4.0.

true

Suppose double x = 18.6. The following statement System.out.println(xx); will not execute resulting in an error.

true

The following statement x++ increments x by 1.

true

What keyword is missing from the method header below? public static displayName( ) { System.out.println("Drake") ; }

void


संबंधित स्टडी सेट्स

Ch. 27 Alterations in Musculoskeletal Fxn

View Set

Special Projections of Digits, Hand, Wrist

View Set

Соціологія. модуль

View Set

Ch. 14 - Functional Diversity of Bacteria

View Set

McCance Huether Pathophysiology Test 1

View Set

CH 7 - Positive Organizational Behavior and Psychological Capital

View Set