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_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_forward3- Enter a=3; b=5; e=7, then clear the variable b only Matlabarrow_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_forwardUsing C Languagearrow_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_forwardInterest on a credit card’s unpaid balance is calculated using the average daily balance. Suppose that netBalanceis the balance shown in the bill, paymentis the payment made, d1is the number of days in the billing cycle, and d2is the number of days payment is made before the billing cycle. Then the average daily balance is: averageDailyBalance = (netBalance * d1 –payment * d2) / d1 if the interest rate per month is say, 0.0152, then the interest on the unpaid balanceis: interest = averageDailyBalance * 0.0152 Design a program that accepts as input netBalance, payment, d1, d2, and interest rate per month. The program outputs the interest charged. Format your output to two decimal places. C++arrow_forwardPROGRAM DESCRIPTION John dela Cruz is interested in knowing how much his interest earning would be after some time. Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as: amount = principal * (1 + rate/m)" interest = amount - principal Principal is the balance in the savings account, rate is the interest rate (0 to 100), m is the number of times the interest is compounded during a year (m is either 1,2,3 or 4 if the interest is compounded quarterly) and nis the number of year., Write a program that asks for the borrower's lastname, borrower's first name, borrower's middle name, civil status (Single, Married, Widow), principal, the interest rate and the number of times the interest is compounded. Follow the format of the report provided in the example. OUTPUT Example 1 Enter the borrower's lastname : Enter the borrower's firstname : Enter the borrower's middle name: Enter civil status : Married Enter the…arrow_forwardWrite a multiple assignment statement that can be used instead of the followinggroup of assignment statements:east = 1;west = 1;north = 1;south = 1;arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning