Concept explainers
Rewrite the following if-else statements as statements that use the conditional operator.
a) if (x > y)
z = 1;
else
z = 20;
b) if {temp > 45)
population = base * 10;
else
population = base * 2;
c) if (hours > 40)
wages *= 1.5;
else
wages *= 1;
d) if (result >= 0}
System.out.println(“The result is positive.”);
else
System.out.println(“The result is negative.”);
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Computer Science: An Overview (12th Edition)
Starting Out with C++: Early Objects
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- Convert the following if statements into a switch statement:if (time == 0){greeting = "Good morning";}else if (time == 1){greeting = "Good day";}else if (time = 2){greeting = "Good evening";}else if (time == 3){greeting = "Good night";}arrow_forwardlanguage is java levelarrow_forwardA- Correct the errors in each of the following statements: 1- if (age >= 65 ); else; 2- if (age >= 65) else 3- int x =1; total; While(x>i>>j; cout<<"Age is greater than or equal to65" << endl; cout << "Age is less than 65 << endl"; cout<arrow_forwardQuestion 10 programming in racket Write a procedure (timezone) that takes no arguments and returns a ; *string* indicating your time zone. ; Remember the difference between a procedure call and the evaluation of a variable! ; Ex: (timezone) => "EST"arrow_forward3. Convert the following switch statement into if-else statements then into if-then statements: String dayString1, dayString2, dayString3; int day = KB.nextInt (); switch (day) { case 1: dayStringl case 2: dayString2 "Saturday"; "Sunday"; break; case 3: dayString3 = "Monday"; break; case 4: dayStringl = "Tuesday"; case 5: daystring2 = "Wednesday"; break; default: dayString3 = "Invalid day"; break; } 4. Write a program that displays the following pattern: A A A A BB AA A ССС AA AA DDDD AAAΑ EEEEE ΑAAAΑΑ FFFFFFarrow_forwardLogical table: Write the truth value of the following logical statementsX=17; Y=35Question;!(Y!=X | | (X<Y)(Y==X) && (X<=Y)arrow_forwardIm use program netbeansarrow_forwardRewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;arrow_forwardCode_Method to check if x is power of 2*/ static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0); }arrow_forwardProblem 2: Employee Payment The Stark Industry needs a program to calculate how much to pay their hourly employees. They have the following rules: An employee gets paid (hours worked) × (base pay), for each hour up to 40 hours. For every hour over 40, they get overtime = (base pay) × 1.5. If the number of hours is greater than 60, print an error message. Example: If an employee works for 45 hours, and his base pay is $8 , the he will get= (40 * 8)+ [5* (8 * 1.5)] = $380 Create a new class called StarkIndustry. Write a method that takes the base pay and hours worked as parameters, and prints the total pay or an error. Write a main method that calls this method for each of these employees: Employee No Base pay Hours Worked Employee 1 $7.20 35 Employee 2 $8.20 47 Employee 2 $10.50 73 You will have to submit StarkIndustry.java file.arrow_forwardWrite a statement that assigns finalValue with the multiplication of userNum1 and userNum2. Ex: If userNum1 is 6 and userNum2 is 2, finalValue is 12. let userNum1 = 6; // Code tested with values: 6 and 4let userNum2 = 2; // Code tested with values: 2 and -2 let finalValue = 0;arrow_forwardGiven the following declarations, evaluate each of the following expressions and give the results. Declarations int I = 16; int a = 14; int b = 3; float c = 6.12; float num, price; double total, sum; Expression Result i = i/3; i = num = c/b*2-b%2; num = total = 12 – static_cast<float>(a)/b; total = price = a*3-static_cast<float>(a)/b; price = sum = static_cast<int>(c/b) + a%b – b/a; sum = please provide an explanation thank you!!arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning