Please answer and explain thank you.
Question 1
What will be printed when the following code is executed?
double x = 45678.259;
System.out.printf("%,.2f", x);
Group of answer choices
45678.259
0,045,678.26
45,678.26
45,678.3
Question 2
What will be printed when the following code is executed?
double x = 45678.259;
String output = String.format("%,.1f", x);
System.out.println(output);
Group of answer choices
45678.259
45,678.259
45,678.26
45,678.3
Question 3
What will be the value of ans after the following code has been
executed?
int ans=0;
for(int i=0; i <= 120; i+=10)
ans += 10;
Group of answer choices
10
130
120
No value, there is a syntax error.
Question 4
What will be the value of bonus after the following code is
executed?
double sal=10000, bonus=0;
if (sal<=10000)
bonus=1000;
else
bonus=500;
Group of answer choices
200
500
750
1000
1250
Question 5
What will be the value of x after the following code is
executed?
int x = 75;
int y = 60;
if (x > y)
x = x - y;
Group of answer choices
75
15
60
135
Question 6
What will be the values of ans, x, and y after the following
statements are executed?
int ans=0, x=0, y=0;
x=+x;
y=+y;
ans=x+y;
y=50;
x=y++;
y+=x;
x=ans;
ans=--y-40;
Group of answer choices
ans = 60, x = 50, y =100
ans = 60, x =0, y =100
ans = 45, x = 50, y = 0
ans = 45, x = 50, y = 50
Question 7
What will be the values of ans, x, and y after the following
statements are executed?
int ans, x, y;
ans=x=y=1;
ans=x++;
y=--x;
Group of answer choices
ans = 0, x = 1, y = 2
ans = 2, x = -1, y = 2
ans = 1, x = 1, y = 1
ans = 1, x = 0, y = 1
Question 8
What would be the value of bonus after the following statements
are executed?
int weeklySal=450;
double bonus=(double)(450/10)
Group of answer choices
100.0
500.0
45.0
Question 9
What would be the value of bonus after the following statements
are executed?
int sal=10000;
if(sal>20000)
bonus=2000;
else if(sal>15000)
bonus=1500;
else if(sal>12500)
bonus=1250;
esle
bonus=1000;
Group of answer choices
2000
1500
1250
1000
Question 10
What would be the value of discountRate after the following
statements are executed?
double purchaseAmount=500;
if(purchaseAmount>1000)
discountRate=.05;
else if(purchaseAmount>800)
discountRate=.03;
else if(purchaseAmount>600)
discountRate=.01;
else
discountRate=0.0;
Group of answer choices
.05
.03
.01
0.0
Question 11
What would be the value of discountRate after the following
statements are executed?
double purchaseAmount=1000;
if(purchaseAmount<=500)
discountRate=0;
else if(purchaseAmount<=700)
discountRate=.01;
else if(purchaseAmount<=800)
discountRate=.03;
else if(purchaseAmount<=900)
discountRate=.04;
else
discountRate=.05;
Group of answer choices
.05
.03
.01
0
Question 12
What would be the value of discountRate after the following
statements are executed?
double purchaseAmount=590;
if(purchaseAmount<500)
discountRate=0;
else if(purchaseAmount<700)
discountRate=.01;
else if(purchaseAmount<800)
discountRate=.03;
else if(purchaseAmount<900)
discountRate=.04;
else
discountRate=.05;
Group of answer choices
.05
.04
.03
.01
Question 13
What would be the value of x after the following statements were
executed?
int x;
for(x=0; x <= 20; x+=5)
System.out.println(x);
Group of answer choices
5
20
25
30
Question 14
Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?
Group of answer choices
if (chr > 'B')
if (chr < 'B')
if (chr != 'B')
if (chr != "B")
Question 15
Which of the following expressions will determine whether x is less than or equal to y?
Group of answer choices
x > y
x =< y
x <= y
x >= y
Question 16
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
Group of answer choices
(x<=500 || x>650) && y !=1000
x<500 && x>650 || y !=1000
(x<500 || x>650) && y !=1000
(x<500 OR x>650) AND y !=1000
Question 17
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?
Group of answer choices
(x<500 OR x>650) AND y NOT EQUAL 1000
x<500 OR x>650 AND y!=1000
x<=500 || x>650 && y !=1000
(x<=500 || x>650) && y !=1000
Question 18
Which of the following will format 12.78 to display as 12.8%?
Group of answer choices
System.out.printf("%2.1d%", 12.78);
System.out.printf("%.2f%%", 12.78);
System.out.printf("%1.2d%", 12.78);
System.out.printf("%.1f%%", 12.78);
Question 19
Which of the following will format 12.7801 to display as $12.78?
Group of answer choices
System.out.printf("$%,.2f", 12.7801);
System.out.printf("%f", 12.7801);
System.out.printf("%.2f$$", 12.7801);
System.out.printf("$d", 12.7801);
Question 20
Which one of the following is the "not equal" operator?
Group of answer choices
NOT=
NOT
*&
!=
Answer 1:
45,678.26
Using "%,.2f" as parameter, the comma "," means to use comma separator for every three digits on the left side of the dot, and the 2 after the dot "." indicates two decimal places for the conversion.
Answer 2:
45,678.3
Using "%,.1f" as parameter, the comma "," means to use comma separator for every three digits on the left side of the dot, and the 1 after the dot "." indicates one decimal place for the conversion.
Answer 3:
130
This for loop will run 13 times and add 10 to ans in every iteration. So 130 is the answer.
Answer 4:
1000.0
Since bonus is double type and sal=10000 which will make true if condition and then bonus will assigned as 1000.So the answer is 1000.0
Answer 5:
15
Since x=75 and y=60 and x>y so x=x-y means x=75-60=15. So, 15 is the answer.
Answer 6:
ans=60,x=0,y=100
The values of ans, x, and y changes as follows after each line:
x=+x; //x=0
y=+y; //y=0
ans=x+y;//ans=0
y=50;
x=y++; //x=50,y=51
y+=x; //x=50,y=101
x=ans; //x=0
ans=--y-40; //ans=60,y=100,x=0
System.out.println(ans); //60
System.out.println(x);//0
System.out.println(y);//100
Answer 7:
Ans=1,x=1,y=1
The values of ans, x, and y changes as follows after each line:
int ans, x, y;
ans=x=y=1;//ans=1,x=1,y=1
ans=x++;//ans=1,x=2,y=1
y=--x;//ans=1,y=1,x=1
System.out.println(ans); //1
System.out.println(x);//1
System.out.println(y);//1
Answer 8:
45.0
450/10=45 and double changes it type to 45.0
Answer 9:
1000
Since sal=10000 which is less than 20000,15000 and 125000 so when else condition execute the bonus =1000 which is answer.
Answer 10:
0.0
Since purchaseAmount=500 which is less than 1000,800,600 so when else condition is execute the discountRate=0.0 .
Answer 11:
0.05
Since purchaseAmount=1000 which is greater than 500,700,800,900 so when else condition is execute the discountRate=0.05 .
Answer 12:
0.01
Since purchaseAmount=590 which is less than 700 so elseif condition execute so discountRate=0.01
Answer 13:
0
5
10
15
20
Since in for loop x=0 it will run till x not equal to 20 so x will increment by adding 5 after each iteration .Hence result will be 0,5,10,15,20 as above.
Answer 14:
if (chr != 'B') is the answer because != (not equal) operator is used to compare with charater b.
But these are not answer because:
if (chr > 'B') //‘>’ is use for greater than
if (chr < 'B') // ‘<’ is use for less than
if (chr != "B")// Here B is not string
Answer 15:
x<=y is the answer.
But these are not answer because:
x > y //It is x greater than y
x =< y //it is invalid operator
x >= y //it is x greater than equal to y
Answer 16:
To test for int x being a value between, but not including, 500 and 650, or int y not equal to 1000
x<500 && x>650 || y !=1000 is the answer because || is logical OR operator and && is logical AND Boolean operator.
But these are not answers because:
1. (x<=500 || x>650) && y !=1000 //Here && operator is used with y
2. (x<500 || x>650) && y !=1000 //Here && operator is used with y
3. (x<500 OR x>650) AND y !=1000 //Here AND/OR are not operator
Answer 17:
To test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000
(x<=500 || x>650) && y !=1000 is the answer.
But these are not answers :
1. (x<500 OR x>650) AND y NOT EQUAL 1000
Here NOT EQUAL/OR are not operators
2. x<500 OR x>650 AND y!=1000
Here x is not equal to 500
3. x<=500 || x>650 && y !=1000
Here bracket is not used to separate the logical operator results.
Answer 18:
Here, System.out.printf("%.1f%%", 12.78); is the answer and it will print 12.78 as 12.8%
But these are not answers:
1. System.out.printf("%2.1d%", 12.78);//illegal format precision
2. System.out.printf("%.2f%%", 12.78); //12.78%
3. System.out.printf("%1.2d%", 12.78);//illegal format precison
Answer 19:
Here, System.out.printf("$%,.2f", 12.7801); is the correct answer it will print 12.7801 to $12.78.
But these are not correct answers :
1. System.out.printf("%f", 12.7801);//12.780100
2. System.out.printf("%.2f$$", 12.7801);//12.78$$
Upto two decimal places and $$also added
3. System.out.printf("$d", 12.7801);//$d
Here $d is not format specifier it will print as it is.
Answer 20:
NOT=
NOT
*&
!=
‘!=’ is the correct relational operator for ‘Not equal’operator and ‘!=’ is the correct answer.
But, ‘NOT=’ , ‘NOT’ ,’*&’ are invalid operators.
Please answer and explain thank you. Question 1 What will be printed when the following code...
QUESTION 1 What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points QUESTION 2 What will be the displayed when the following code...
Eclipse Java Oxygen Question 11 pts A compile-time error occurs when Group of answer choices c. there’s a syntax error in a Java statement a. the Java compiler can’t be located b. bytecodes can’t be interpreted properly c. there’s a syntax error in a Java statement Flag this Question Question 21 pts An error that lets the application run but produces the wrong results is known as a Group of answer choices d. syntax error c. logic error a. runtime...
MICROSOFT VISUAL STUDIO C++: 13. What will be printed when the following statements are executed? int x = 0, y = 0; do { if(x == y) x= x + 1; else y=y — 1; } while (x<y + 4); cout << “y=“ <<y <<“ X=" << x << endl;
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8}; for(int i=0;i<9;i++) a[i]=a[i+1]; for(int i=0;i<8;i++) cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){ if(a[i]==' '){ c++; cout<<endl; } else cout<<a[i]; i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College"; for (i...
Please explain the following so I can do them for myself, thank you very much If the following C program were to be compiled, linked, and executed, it would print the value of x . How many zeros would appear to the left of the 1 ? #include <stdio.h> int main() { int x = 1234 ; printf ( "%15.6d\n", x ) ; return 0 ; } The answer is 2 If the following C...
Please answer both questions thank you. Question 39 (1 point) Translate the following conditions to Java, where x is an integer and s is a string. 1. x >= 6 2. x < 0 s is "Day" 3. S = "Day" x is at least 6 4. X == -7 DODO x is at most 6 5. x = -7 x is - 7 6. s.equals("Day") 7. x <= 6 x is not 27 8. X >O x is positive...
QUESTION 15 Which does not represent a mode a data file may be opened in using C? O execute, "e append, "a O write, "w" O read, " QUESTION 16 You need to read temperatures until a threshold is reached. The statements in the loop must be executed at least once. What type of structure should be used to do this? 0 while O none of these O do/while O for QUESTION 17 Give the value of time after the...
C programming Given an integer variable declared as int result, which of the following choices set result = 2? Each choice may contain a single statement or a group of statements. Select all choices you believe are correct--this question may have more than one correct answer! A. double temp = 19.0; int div = 10; result = 1 + temp / div; B. double val1 = 3; double val2 = 0.75; result = val1 / 2 + val2 * 2; C....
java a. What is printed by the following code? Explain your answer by showing how you computed the values of pos, s1, s2 and 53. String str = "2900 Bedford Ave Brooklyn NY 12230-6843"; int pos = str.indexOf(" ", str.indexOf(" ", 'B') + 1); String si = str.substring(o, pos); System.out.println("pos: + post sl: + sl); pos - str.indexOf("B", pos+1); pos = str.indexOf("B", pos+1); String s2 = str.substring(pos, str. indexOf(" ", pos)): System.out.println("pos: + pos + + s2); String s3 =...