What is the output of the following two lines of Java code?
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Mechanics of Materials (10th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Web Development and Design Foundations with HTML5 (8th Edition)
Concepts Of Programming Languages
Database Concepts (8th Edition)
- In Java code: What is the output of the following code? int x = 0;if (x < 4) {x++;}System.out.println("x is " + x);arrow_forwardIn JAVA ASSIGNMENT DESCRIPTION: A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 24 hours. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:System.out.printf("After 6 hours: %.2f mg\n", yourValue); Ex: If the input is: 100 the output is: After 6 hours: 50.00 mg After 12 hours: 25.00 mg After 24 hours: 6.25 mg Note: A cup of coffee has about 100 mg. A soda has about 40 mg. An "energy" drink (a misnomer) has between 100 mg and 200 mg. THE CODE I HAVE SO FAR: import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double caffeineMg; // "double" supports floating-point like 75.5, versus int for integers like 75. caffeineMg = scnr.nextDouble(); System.out.printf("After…arrow_forwardWrite a program that displays the following pattern: In java * *arrow_forward
- .Write a java program: Your program will input 2 integer values from the command line. (Remember thecommand-line input enters your program through main() method. You'll need to convert thevalues from String data type to integer data type. Use Integer.parseInt() method.)Using the two values entered (which could be any integers), create the following outputstatements (the example assumes the input values were 10 and 14):10 + 14 = 2410 - 14 = -410 X 14 = 14010 / 14 = 010 % 14 = 10You will have 5 lines of output. Put spaces in your output as shown in the sample output.arrow_forwardHow do I code: If the difference is positive, return “a is bigger by” + diff. If the difference is negative, return “b is bigger by” + diff. If there is NO difference between the two numbers, return “EQUAL” in Java.arrow_forwardWhat is the result of the following code segment in Java? int x-38; System.out.println(++x); O a. 38 O b. 39 Ос. 37 O d. 40arrow_forward
- Coronavirus (COVID-19) is causing a lot of panic the world over. Most people in developing countries are panicking because there are not proper test kids to determine whether one has the virus or not. You have been consulted to develop a program that could be used as a first step in determining the likelihood that one has it or not so that persons could then be referred to the testing center to be tested. Your task is to:a. Write a java program that request for1. A person’s age2. Temperature3. Dry cough4. Sneezing5. Running nose b. Your program should refer to the testing center when:1. Temperature >38oC and Sneezing, Running nose, Dry cough allrespond to yes 2. Or Temperature >38oC and any two from “a 3 – 5” above all respondto yes 3. Otherwise your program shouldn’t display go homearrow_forwardjavaarrow_forwardi'm still confused on how to complete this, is there anyway you could help?arrow_forward
- I need help with creating a Java program described below: A Game of Twenty-One: Write a program that lets the user play against the computer in a variation of the popular blackjack card game. In this variation of the game, two six-sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer’s hidden total without going over 21. Here are some suggestions for the game’s design: Each round of the game is performed as an iteration of a loop that repeats as long as the player agrees to roll the dice, and the player’s total does not exceed 21. At the beginning of each round, the program will ask the user whether or not he or she wants to roll the dice to accumulate points. During each round, the program simulates the rolling of two six-sided dice. It rolls the dice first for the computer, and then it asks the user whether he or she wants to roll. Create a Die class to use with this application. The loop keeps a running total of both the computer…arrow_forwardIn Java A variable like userNum can store a value like an integer. Extend the given program to print userNum values as indicated. (Submit for 2 points). (1) Output the user's input. Enter integer: 4 You entered: 4 (2) Extend to output the input squared and cubed. Hint: Compute squared as userNum * userNum. (Submit for 2 points, so 4 points total). Enter integer: 4 You entered: 4 4 squared is 16 And 4 cubed is 64!! (3) Extend to get a second user input into userNum2. Output sum and product. (Submit for 1 point, so 5 points total). Enter integer: 4 You entered: 4 4 squared is 16 And 4 cubed is 64!! Enter another integer: 5 4 + 5 is 9 4 * 5 is 20 import java.util.Scanner; public class OutputWithVars {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int userNum = 0; System.out.println("Enter integer: ");userNum = scnr.nextInt();return;}}arrow_forwardanswer in java: How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed. The formula is twc = 35.74 + 0.6215ta − 35.75v0.16 + 0.4275tav0.16 where ta is the outside temperature measured in degrees Fahrenheit and v is the speed measured in miles per hour. twc is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below −58°F or above 41°F. Write a program that prompts the user to enter a temperature between −58°F and 41°F and a wind speed greater than or equal to 2 and displays the wind-chill temperature. Use Math.pow(a, b) to compute v0.16.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