Concept explainers
Given that the int variable temp contains a temperature that is not negative, write a Java statement that uses the conditional operator to set the String variable label to either “degree” or “degree”. We want to use label to produce grammatically correct output, such as 0 degrees, 1 degree, 2 degrees, and so on. If you have not studied the conditional operator, use an if-else statement instead.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Python (3rd Edition)
C Programming Language
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
- In java, How can the following statement be rewritten using a conditional operator?if(x <0) y = x;else y = 0;arrow_forwardHello..Its no correct....Can you help me?arrow_forwardWrite a program that reads the temperature and unit from the user and prints a message indicating if it’s hot, cool or cold. The user may enter the temperature either in Fahrenheit or in Celsius. Below are the intervals. Your program should use nested if-else statements. If the input is invalid, print an error message and terminate the program.arrow_forward
- The objective of this program is to demonstrate your proficiency with the if-elif-else construct. Your program will consist of a simple guessing game. Using the random module, generate an integer between 1 and 10. This will be the secret. You will then ask the user for a guess between 1 and 10. . If the guess is greater than the secret respond, "Too high". • If the guess is less than the secret respond, "Too low". . If both numbers are equal respond, "Success!". Remember to test your program to ensure that all of the comparisons work. Please note that a loop is not required. The images below shows the program being run multiple times to display the three different possible output messages. Your display should look like this. User input is highlighted in green. Please enter your guess: 10 Too high! Please enter your guess: 5 Too low! Please enter your guess: 1 Success!arrow_forwardbasic JAVAarrow_forwardWrite an if statement in Java that prints "Pass" if the grade is greater than or equal to 70 and prints "Fail" if the grade is below 70. If the grade is below 70 print "You have to do Exam2."arrow_forward
- javaarrow_forwardWrite a program that prints the insurance fee to pay for a pet according to the following rules: (Note: must use a switch statement to determine pet fee) A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been neutered costs $40.A cat that has not been neutered costs $60.A bird or reptile costs nothing.Any other animal generates an error message. The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered status(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case. It prints out the type of animal (full name of animal)…arrow_forwardCan you please help write this with java levelarrow_forward
- i need the answer quicklyarrow_forwardWrite a C++ program that will ask for a number which will determine the grading system. If the number is between 90 and 100, display "Excellent". If the number is between 80 and 91, display "Well done". If the number is between 70 and 81, display "Good". If the number is between 60 and 71, display "Better luck next time". If the number is between 50 and 61, display "Needs more effort". If the number is between 0 and 50, display "Failed".arrow_forwardBelow is a Boolean expression. Write a block of conditional statements (if/elif/else) that will cause the phrase "It works!" to be printed if and only if the Boolean expression evaluates to True. Your code should not use any logical operators (and/or/not), only conditionals and prints (and pass if necessary). You may assume that first, second, third, and fourth are variables which have already been defined as either True or False. (first or not second) and not (third or fourth)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education