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
MyLab Programming with Pearson eText -- Access Code Card -- for Starting Out with Java: From Control Structures through Objects
Additional Engineering Textbook Solutions
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Database Concepts (8th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
SURVEY OF OPERATING SYSTEMS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- C++arrow_forwardUsing c++ write a program : Write a program in C++ to handle the following scenario: Three friends Asif, Shahid and Bashir start the business. Input following from user. Enter amount invested by Asif (user will enter any value) Bashir’s contribution is equal to 250% of Asif’s contribution and Shahid’s contribution is equal to 75% of Bashir’s contribution. Display amount contributed by Bashir and Shahid. After 6 months business earned profit of 50% of total investment. Display the total profit and the amount each sharer will get (i.e. distribute profit as per percentage of their investment).arrow_forwardConvert 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_forward
- language is java levelarrow_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_forward
- 3. 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_forward
- Code to call your function e C Reset 1 CalculateDosage(65)arrow_forwardRewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;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_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning