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 plus MyProgrammingLab with Pearson eText -- Access Card Package (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)
- Create a Java program that declares and initializes an integer variable "num" with a value of your choice. Use the "if-then" statement to check if "num" is even or odd. If "num" is even, output a message to the console indicating that it is even. If "num" is odd, output a message to the console indicating that it is odd. Use the "if-then-else" statement to check if "num" is positive or negative. If "num" is positive, output a message to the console indicating that it is positive. If "num" is negative, output a message to the console indicating that it is negative. If "num" is zero, output a message to the console indicating that it is zero. Use a nested "if-then-else" statement to check if "num" is divisible by 2 and 3. If "num" is divisible by 2 and 3, output a message to the console indicating that it is divisible by both. If "num" is only divisible by 2, output a message to the console indicating that it is only divisible by 2. If "num" is only divisible by 3, output a message…arrow_forwardSuppose number is a variable of type int. Write an if-else statement thatoutputs the word "Positive" if the value of the variable number is greater than0 and outputs the words "Not positive" if the value of number is less than orequal to 0.arrow_forwardCreate a Java program that declares and initializes a string variable "dayOfWeek" with a value of your choice (e.g., "Monday", "Tuesday", etc.). Use a "switch" statement to check the value of "dayOfWeek" and output a message to the console indicating the corresponding day of the week. For example, if "dayOfWeek" is "Monday", output a message saying "Today is Monday". Use "default" to output a message for any invalid value of "dayOfWeek".arrow_forward
- The following is related to a Java Code: The following if statement determines whether choice is equal to ‘Y’ or ‘y’: if (choice == 'Y' || choice == 'y') Rewrite this statement so it makes only one comparison and does not use the || operator. 1) How will it get fixed?arrow_forwardWrite a Java expression that is the opposite of the following range. You MAY NOT simply use a NOT, e.g., !(m <=10|| m >= 20) will not be accepted. m <= 10 || m >= 20arrow_forwardWrite a Java program that asks the user to input the jackets quality in any letter case (HQL for high quality , LQL for low quality ) and their prices in factory, until the user enter QUIT in any case letter to stop. your program should count the number og HQL and LQL jackets, as well as the HQL price of jackets, then print the result on the screen. your program should ignore any unknown jacket quality.arrow_forward
- Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Javaarrow_forwardThis is in JAVA. Which expressions for YYY and ZZZ correctly output the indicated ranges? Assume int x's value will be 0 or greater. Choices are in the form YYY / ZZZ. if(YYY){// Output "0-29"} else if (ZZZ) {// Output "30-39"}else {// Output "40+"} A. x < 29 / x >= 29 B. x < 30 / x >= 30 C. x < 30 / x < 40 D. x > 29 / x > 40arrow_forwardHello, I need a Java code (without using the if statement) that sum the rational numbers from the user so the output of 2/3 + 3/2 is 13/6 please notice that is it so important to write it without the if statement, we just ask the user to not write zero.arrow_forward
- Java Fill in the blank to complete the code so that it will print out "looks good" if the value of the integer variable input is within the range of 1 through 10. Do not use any additional parentheses in your answer. if (____________________) { System.out.println("looks good");}arrow_forwardWrite a program that will figure out the required change for a purchase. Start by asking the user for the price of the product and the amount paid. (We are expecting that the user will give a larger value for the amount paid.) Read in each of these values as a double. Report back to the user the number of each denomination of change due. You are not just telling the user the amount of money he gets back. Hint: Working with integers is much easier. The modulo operator is your friend for this assignment. Also, note that pennies can be tricky due to the poor real number to binary conversions. (Remember that 1.00 could actually be stored as 0.9999999999997.) Do not include five-dollar bills, ten-dollar bills, etc. Only show coins and one-dollar bill amounts. Be sure to test multiple values. There is a test case below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output Example (User input is marked with >>>.…arrow_forwardWrite a program that works out if a given year is a leap year This is how to workout whether if a perticular year is a leap year on every year that is evenly divisible by 100 except every year that is evenly divisible by 100 unless the year is also evenly divisible by 400 Note Study the flow chart given below START No Yesit cleanly divisible by Not Leap No Yes it cleanly divisible by 1007 Leap No Yes it cleanly divisible by 4007 Not Leap Leap Guideline : Create a unique code Create a function leapYear_697 to accept the parameter (i.e year ) and return whether the given year is a leap year Javascript program name should be like Assign2 697arrow_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