Concept explainers
Suppose, when you run the following
public class Test {
public static void main(String[] args) {
java.util.Scanner Input = new java.util.Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
double z = input.nextDouble();
System.out.println(“(x < y && y < z) is ” + (x < y && y < z));
System.out.println(“(x < y || y < z) is ” + (x < y || y < z));
System.out.println(“!(x < y) is ” + !(x < y));
System.out.println(“(x + y < z) is ” + (x + y < z));
System.out.println(“(x + y > z) is ” + (x + y > z));
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Starting Out with C++: Early Objects (9th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
- Java - How do I output this statement as a horizontal statement with a newline? Everytime I use System.out.println, it makes the entire output vertical instead of horizontal. Program below. import java.util.Scanner; public class LabProgram { public static void main(String[] args) { int x; int y; Scanner scan = new Scanner(System.in); x = scan.nextInt(); y = scan.nextInt(); if(y >= x){ for(int i=x; i<=y; i = i + 5) { System.out.print(i+ " "); (The problem line) } } else{ System.out.print("Second integer can't be less than the first."); } }}arrow_forwardimport java.util.*;public class TestAverage {public static void main(String[] args) {int test1, test2, test3, sum;Scanner reader = new Scanner(System.in);System.out.println("Enter test 1");test1 = reader.nextInt();System.out.println("Enter test 2");test2 = reader.nextInt();System.out.println("Enter test 3");test3 = reader.nextInt();sum = test1 + test2 + test3;System.out.println("The sum is " + sum);System.out.println("The average is " + sum / 3);}}a. Briefly explain what this code does.b. There is one logic error in this code explain what is wrong and how to fix it.arrow_forwardimport java.util.*; public class CardGame { static Scanner scanner = new Scanner(System.in); static Random random = new Random(); public static void main(String[] args) { System.out.println("Welcome to the card game! Here are the instructions:"); System.out.println("- You will randomly draw a card from a deck of 52 cards."); System.out.println("- The computer will also draw a card from the same deck."); System.out.println("- If your card has a higher face value, you win. Otherwise, you lose."); System.out.println("- If your card has the same face value as the computer's card, the suit determines the order."); int gamesPlayed = 0; int userWins = 0; int computerWins = 0; boolean[] cards = new boolean[52]; // false means the card is available, true means it's been drawn while (true) { System.out.println("\nNew game!"); int[] userCard = drawCard(cards); int[]…arrow_forward
- Write an expression that will cause the following code to print "I am an adult" if the value of userAge is greater than 19. 1 import java.util.Scanner; 3 public class AgeChecker { public static void main (String ] args) { 4 int userAge; 7 Scanner scnr = new Scanner(System.in); userAge = scnr.nextInt(); // Program will be tested with values: 18, 19, 20, 21. 8 9 10 if (//your code goes here) { System.out.println("I am a teenager"); } else { System.out.println("I am an adult"); } } 11 12 13 14 15 16 17 18 }arrow_forwardWrite code that outputs variable numPens as follows. End with a newline. Ex: If the input is: 4 the output is: Will there be 4 pens? import java.util.Scanner; public class OutputTest { public static void main (String [] args) { int numPens; // Our tests will run your program with input 4, then run again with input 7. // Your program should work for any input, though. Scanner scnr = new Scanner(System.in); numPens = scnr.nextInt(); System.out.println("Will there" + "be 4 pens?"); }}arrow_forwardclass Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}} What will the given code prints on the output screen.arrow_forward
- import java.util.Scanner;/** This program calculates the geometric and harmonic progression for a number entered by the user.*/public class Progression{ public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println("This program will calculate " + "the geometric and harmonic " + "progression for the number " + "you enter."); System.out.print("Enter an integer that is " + "greater than or equal to 1: "); int input = keyboard.nextInt(); // Match the method calls with the methods you write int geomAnswer = geometricRecursive(input); double harmAnswer = harmonicRecursive(input); System.out.println("Using recursion:"); System.out.println("The geometric progression of " + input + " is " + geomAnswer); System.out.println("The harmonic progression of " +…arrow_forwardWrite code that outputs variable numBirds as follows. End with a newline. Ex: If the input is: 3 the output is: Birds: 3 1 import java.util.Scanner; 2 3 public class OutputTest { public static void main (String [] args) { int numBirds; 4 // Our tests will run your program with input 3, then run again with input 6. // Your program should work for any input, though. Scanner scnr = new Scanner(System.in); 7 8 10 numBirds scnr.nextInt(); 11 12 /* Your code goes here */ 12arrow_forward// ArtShow.java - This program determines if an art show attendee gets a 5% discount // for preregistering. // Input: Interactive. // Output: A statement telling the user if they get a discount or no discount. import java.util.Scanner; public class ArtShow { public static void main(String args[]) { Scanner s = new Scanner(System.in); String registerString; System.out.println("Did you preregister? Enter Y or N: "); registerString = s.nextLine(); // Test input here. If Y, call discount(), else call noDiscount(). System.exit(0); } // End of main() method. // Write discount method here. // Write noDiscount method here. } // End of ArtShow class.arrow_forward
- I have my code here and I am getting errors (I have also attached my code): " import java.util.Compiler; public class Test Score { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Ënter the first exam Score: "); Double Score1 = scan.nextDouble(); System.out.println("Enter the second exam Score: "); Double Score2 = scan.nextDouble(); System.out.println("Enter the third exam Score: "); Double Score3 = scan.nextDouble(); System.out.println("Enter the fourth exam Score: "); Double Score4 = scan.nextDouble(); System.out.println("Enter the fifth exam Score: "); Double Score5 = scan.nextDouble(); Double total = Score1 + Score2 + Score3 + Score4 + Score5 Double average = total/5; if (average >= 90) { System.out.printf("your average was a: %f and recieved an A in this Class", average ); } else if (average >= 80) {…arrow_forward1. What is the output of the following code? public class Loopy {public static void main(String[] args) {int x = 1;System.out.println("Before the loop");while (x < 4) {System.out.println("In the loop");System.out.println("Value of x is " + x);x = x + 1;}System.out.println("This is after the loop");}} 2. Write a program called KiloToPoundTable that prints the below table. Useprintf()and while statement. Do not use if while statement. 1) 1 kilogram is 2.20462 pounds (so, 2nd row will be 3 * 2.20462)2) Use while statement to iterate3) Set width to 12 for each column4) Use printf() for precision up to tenths placearrow_forwardThe following program has 10 blanks, all of which can be deduced from other given parts of the program. blank java.util.Scanner; public class Perimeter { public static Blank main(String [] args) { double length, width, Blank ; Scanner Blank= new Scanner(); System.Blank .print("Enter the length of the rectangle: "); length = scan.nextDouble(); System.out.print("Enter the width of the rectangle: "); width = scan.next Blank(); perimeter = Blank*2 + width*2; System.out. ("%s%f%s, "The perimeter of the rectangle is " + Blank + " inches."); }//end blank method }//end classarrow_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