This file contains bidirectional Unicode message that might be taken or compiled in different way than what appears below. Come review, open up the file in one editor that reveals covert Unicode characters. Learn more about bidirectional Unicode characters
The adhering to program has 9 errors. Correct the errors and submit a working version of the program. The corrected variation of the regime should develop the complying with output:
x is 0
x is currently 15
x and also y are 15 and also 16
// uncover ERRORS
public class Oops2 
public static void main(String<> args) 
int x;
System.out.println("x is " x);
int x = 15.2; // set x to 15.2
System.out.println("x is now + x");
int y; // set y to 1 more than x
y = int x + 1;
System.out.println("x and y are " + x + and + y);
// Solution
public class Oops2 
public static void main(String<> args) 
int x = 0;
System.out.println("x is " + x);
x = 15; // set x to 15
System.out.println("x is now " + x);
int y = 0; // set y to 1 more than x
y = x + 1;
System.out.println("x and y are " + x + " and " + y);

This record contains bidirectional Unicode message that may be understood or compiled in different way than what shows up below. Come review, open up the document in one editor the reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Suppose you have actually an int variable referred to as number. What Java expression to produce the second-to-last digit of the number (the 10s place)?
What expression to produce the third-to-last number of the number (the 100s place)?
number / 10 % 10
number / 100 % 10

This paper contains bidirectional Unicode text that may be construed or compiled differently than what shows up below. Come review, open up the record in one editor that reveals hidden Unicode characters. Learn an ext about bidirectional Unicode personalities
What is the value of change x after the adhering to code executes?
int x = 3;
x = x + 2;
x = x + x;
A:
10

This record contains bidirectional Unicode message that may be taken or compiled in different ways than what shows up below. Come review, open up the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
What room the worths of a, b, and c ~ the complying with code statements?
int a = 5;
int b = 10;
int c = b;
a = a + 1;
b = b - 1;
c = c + a;
A;
a = 6
b = 9
c = 16

This record contains bidirectional Unicode message that might be understood or compiled differently than what appears below. Come review, open the document in an editor the reveals hidden Unicode characters. Learn an ext about bidirectional Unicode personalities
What room the values of very first and 2nd at the finish of the following code?
int very first = 8;
int second = 19;
first = first + second;
second = an initial - second;
first = first - second;
A:
first = 19
second = 8

This document contains bidirectional Unicode message that might be understood or compiled differently than what shows up below. Come review, open up the file in an editor that reveals covert Unicode characters. Learn an ext about bidirectional Unicode personalities
Rewrite the adhering to code indigenous the previous exercise to be shorter, by proclaiming the variables together on the very same line,
and by utilizing the special assignment operators (e.g., +=, -=, *=, and /=) together appropriate.

You are watching: Bjp4 self-check 2.5: expressions3

int first = 8;
int 2nd = 19;
first = very first + second;
second = an initial - second;
first = an initial - second;
A:
int first = 8, second = 19;
first += second;
second = first - second;
first -= second;

This paper contains bidirectional Unicode message that might be construed or compiled in different way than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
What are the values of i, j, and k after the adhering to code statements?
int ns = 2;
int j = 3;
int k = 4;
int x = ns + j + k;
i = x - ns - j;
j = x - j - k;
k = x - ns - k;
A:
i = 4
j = 2
k = 1

This record contains bidirectional Unicode text that might be taken or compiled in different way than what appears below. Come review, open the record in an editor the reveals surprise Unicode characters. Learn more about bidirectional Unicode personalities
int max;
int min = 10;
max = 17 - 4 / 10;
max = max + 6;
min = max - min;
System.out.println(max * 2);
System.out.println(max + min);
System.out.println(max);
System.out.println(min);
A:
46
36
23
13

This document contains bidirectional Unicode message that might be taken or compiled in different way than what shows up below. Come review, open up the paper in one editor that reveals concealed Unicode characters. Learn much more about bidirectional Unicode personalities
The complying with program redundantly repeats the very same expressions many times.
Modify the regimen to remove all redundant expressions using variables of appropriate types.
public course ComputePay
public revolution void main(String<> args)
// calculation pay at work based on hours worked each day
System.out.println("My full hours worked:");
System.out.println(4 + 5 + 8 + 4);
System.out.println("My hourly salary:");
System.out.println("$8.75");
System.out.println("My total pay:");
System.out.println((4 + 5 + 8 + 4) * 8.75);
System.out.println("My count owed:"); // 20% tax
System.out.println((4 + 5 + 8 + 4) * 8.75 * 0.20);
public class ComputePay 
public static void main(String<> args) 
// Calculate pay at work based on hours worked each day
int totalHours = 4 + 5 + 8 + 4;
double hourlyPay = 8.75;
dual totalPay = (totalHours) * hourlyPay;
twin taxesOwed = (totalHours) * hourlyPay * 0.20;
System.out.println("My total hours worked:");
System.out.println(totalHours);
System.out.println("My hourly salary:");
System.out.println("$" + hourlyPay);
System.out.println("My total pay:");
System.out.println(totalPay);
System.out.println("My taxes owed:"); // 20% tax
System.out.println(taxesOwed);

This file contains bidirectional Unicode text that might be taken or compiled differently than what shows up below. To review, open the paper in an editor the reveals surprise Unicode characters. Learn more about bidirectional Unicode characters
Which the the adhering to are legit int literals?
22
5.
2.3
10.0
1.5
'7'
-6875309
-1
A:
22
-6875309
-1

This document contains bidirectional Unicode text that might be construed or compiled in different way than what appears below. Come review, open up the paper in one editor the reveals covert Unicode characters. Learn an ext about bidirectional Unicode characters
The adhering to program redundantly repeats the very same expressions numerous times.
Modify the program to remove all redundancy expressions making use of variables of ideal types.
// This program computes the total amount owed for a meal,
// assuming 8% tax and a 15% tip.

See more: What Is The Power Of One Laser Pulse? Lecture 7 Energy And Intensity

public class Receipt 
public static void main(String<> args) 
System.out.println("Subtotal:");
System.out.println(38 + 40 + 30);
System.out.println("Tax:");
System.out.println((38 + 40 + 30) * .08);
System.out.println("Tip:");
System.out.println((38 + 40 + 30) * .15);
System.out.println("Total:");
System.out.println(38 + 40 + 30 +
(38 + 40 + 30) * .08 +
(38 + 40 + 30) * .15);
public class Receipt 
public static void main(String<> args) 
int subTotal = 38 + 40 + 30;
twin taxOnTotal = subTotal * 0.08;
double totalWTip = subTotal * 0.15;
double total = subTotal + taxOnTotal + totalWTip;
System.out.println("Subtotal:");
System.out.println(subTotal);
System.out.println("Tax:");
System.out.println(taxOnTotal);
System.out.println("Tip:");
System.out.println(totalWTip);
System.out.println("Total:");
System.out.println(total);

This record contains bidirectional Unicode message that might be taken or compiled in different ways than what shows up below. To review, open up the file in one editor that reveals concealed Unicode characters. Learn an ext about bidirectional Unicode characters
Complete the complying with code, replacing the "FINISH ME" components with your own code, to develop the adhering to output:
2 time 1 = 2
2 time 2 = 4
2 time 3 = 6
2 times 4 = 8
public course Count2 {
public static void main(String<> args) {
because that (int ns = 1; i raw
This record contains bidirectional Unicode message that may be interpreted or compiled in different way than what appears below. Come review, open the record in one editor that reveals covert Unicode characters. Learn much more about bidirectional Unicode characters
What is the output of the adhering to oddStuff method?
public static void oddStuff() {
int number = 4;
because that (int count = 1; counting raw
This paper contains bidirectional Unicode text that may be interpreted or compiled in different ways than what shows up below. To review, open the record in one editor that reveals hidden Unicode characters. Learn an ext about bidirectional Unicode personalities
What is the output of the complying with loop?
System.out.println("+----+");
for (int ns = 1; i raw

life

life

raw
Trace the review of the following expressions, and give your resulting values.
Make sure to provide a value of the appropriate type (such as consisting of a .0 at the end of a twin or quotes approximately a String).
2 + 2 + 3 + 4= 11
"2 + 2 " + 3 + 4= "2 + 2 34"
2 + " 2 + 3 " + 4= "2 2 + 3 4"
3 + 4 + " 2 + 2"= "7 2 + 2"
"2 + 2 " + (3 + 4)= "2 + 2 7"
"(2 + 2) " + (3 + 4)= "(2 + 2) 7"
"hello 34 " + 2 * 4= "hello 34 8"
2 + "(int) 2.0" + 2 * 2 + 2= "2(int) 2.042"
4 + 1 + 9 + "." + (-3 + 10) + 11 / 3= "14.73"
8 + 6 * -2 + 4 + "0" + (2 + 5)= "007"
1 + 1 + "8 - 2" + (8 - 2) + 1 + 1= "28 - 2611"
5 + 2 + "(1 + 1)" + 4 + 2 * 3= "7(1 + 1)46"
"1" + 2 + 3 + "4" + 5 * 6 + "7" + (8 + 9)= "123430717"



life

life

life

raw

life
<br> <br> <br> <h3> <img class=bjp4 self-check 2.5: expressions3 -->