Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 1.7, Problem 1.7.5CP
Explanation of Solution
Output of the program:
// Class definition
public class Test
{
// Main class definition
public static void main(String[] args)
{
// Display the string output
System .out . println("3.5 * 4 / 2 - 2.5 is " );
// Display the computed value
System .out .println (3.5 * 4 / 2 - 2.5);
}
}
Sample Output:
3.5 * 4 / 2 - 2.5 is
4...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
class isNaN_output
{
public static void main(String args[])
{
Double d = new Double(1 / 0.);
boolean x = d.isNaN();
System.out.print(x);
}
}
What will the given code prints on the output screen.
//Assignment 06 */public static void main[](String[] args) { String pass= "ICS 111"; System.out.printIn(valPassword(pass));}
/*
public static boolean valPassword(String password){ if(password.length() > 6) { if(checkPass(password) { return true; } else { return false; } }else System.out.print("Too small"); return false;}
public static boolean checkPass (String password){ boolean hasNum=false; boolean hasCap = false; boolean hasLow = false; char c; for(int i = 0; i < password.length(); i++) { c = password.charAt(1); if(Character.isDigit(c)); { hasNum = true; } else if(Character.isUpperCase(c)) { hasCap = true; } else if(Character.isLowerCase(c)) { hasLow = true; } } return true; { return false; }
}
// SuperMarket.java - This program creates a report that lists weekly hours worked
// by employees of a supermarket. The report lists total hours for
// each day of one week.
// Input: Interactive
// Output: Report.
import java.util.Scanner;
public class SuperMarket
{
public static void main(String args[])
{
// Declare variables.
final String HEAD1 = "WEEKLY HOURS WORKED";
final String DAY_FOOTER = " Day Total "; // Leading spaces are intentional.
final String SENTINEL = "done"; // Named constant for sentinel value.
double hoursWorked = 0; // Current record hours.
String hoursWorkedString = ""; // String version of hours
String dayOfWeek; // Current record day of week.
double hoursTotal = 0; // Hours total for a day.
String prevDay = ""; // Previous day of week.
boolean done = false; // loop control
Scanner input = new…
Chapter 1 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 1.2 - What are hardware and software?Ch. 1.2 - List the five major hardware components of a...Ch. 1.2 - What does the acronym CPU stand for? What unit is...Ch. 1.2 - Prob. 1.2.4CPCh. 1.2 - What is memory for? What does RAM stand for? Why...Ch. 1.2 - Prob. 1.2.6CPCh. 1.2 - Prob. 1.2.7CPCh. 1.3 - What language does the CPU understand?Ch. 1.3 - What is an assembly language? What is an...Ch. 1.3 - What is a high-level programming language? What is...
Ch. 1.3 - What is an interpreter? What is a compiler?Ch. 1.3 - Prob. 1.3.5CPCh. 1.4 - Prob. 1.4.1CPCh. 1.4 - Prob. 1.4.2CPCh. 1.4 - Prob. 1.4.3CPCh. 1.5 - Who invented Java? Which company owns Java now?Ch. 1.5 - What is a Java applet?Ch. 1.5 - What programming language does Android use?Ch. 1.6 - What is the Java language specification?Ch. 1.6 - Prob. 1.6.2CPCh. 1.6 - Prob. 1.6.3CPCh. 1.6 - Are tools like NetBeans and Eclipse different...Ch. 1.7 - What is a keyword? List some Java keywords.Ch. 1.7 - Prob. 1.7.2CPCh. 1.7 - Prob. 1.7.3CPCh. 1.7 - Prob. 1.7.4CPCh. 1.7 - Prob. 1.7.5CPCh. 1.8 - What is the Java source filename extension, and...Ch. 1.8 - What are the input and output of a Java compiler?Ch. 1.8 - What is the command to compile a Java program?Ch. 1.8 - What is the command to run a Java program?Ch. 1.8 - Prob. 1.8.5CPCh. 1.8 - Prob. 1.8.6CPCh. 1.8 - If a NoClassDefFoundError occurs when you run a...Ch. 1.8 - If a NoSuchMethodError occurs when you run a...Ch. 1.9 - Reformat the following program according to the...Ch. 1.10 - Prob. 1.10.1CPCh. 1.10 - Prob. 1.10.2CPCh. 1.10 - If you forget to put a closing quotation mark on a...Ch. 1.10 - If your program needs to read integers, but the...Ch. 1.10 - Suppose you write a program for computing the...Ch. 1.10 - Identify and fix the errors in the following code:...Ch. 1 - (Display three messages) Write a program that...Ch. 1 - (Display five messages) Write a program that...Ch. 1 - (Display a pattern) Write a program that displays...Ch. 1 - Prob. 1.4PECh. 1 - (Compute expressions) Write a program that...Ch. 1 - (Summation of a series) Write a program that...Ch. 1 - (Approximate ) can be computed using the...Ch. 1 - (Area and perimeter of a circle) Write a program...Ch. 1 - (Area and perimeter of a rectangle) Write a...Ch. 1 - (Average speed in miles) Assume that a runner runs...Ch. 1 - (Population projection) The U.S. Census Bureau...Ch. 1 - (Average speed in kilometers) Assume that a runner...Ch. 1 - (Algebra: solve 2 2 linear equations) You can use...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Examine this code and determine what happens when it is run: 1 public class Test { int x; 2 3 public Test(String t){ System.out.println("Test"); } public static void main(String[] args) { Test test = new Test ("boo"); System.out.println(test.x); } 4 5 6 7 8 10 } The program has a compile error because Test does not have a default constructor. The program has a compile error because System.out.println method cannot be invoked from the constructor. ) The program runs successfully and prints out: Test O The program has a compile error because you cannot create an object from the class that defines the object.arrow_forwardQUESTION 4 Analyze the following code: public class Test { public static void main (String [] args) { int i = 0; while (i ++ < 10); System.out.println(i + 4); The program compiles despite the semicolon () on the for loop line, and displays 15. The program has a compile error because of the semicolon (;) on the while loop line. The program compiles despite the semicolon (:) on the while loop line, and displays 4.arrow_forwardRead the following code. The purpose is to test if str2 is equal to str3. public class StringEqual { public static void main(String[] args) { String str1 = "abcd"; String str2 = "abcdefg"; String str3 = str1 + "efg"; System.out.println("str2 = " + str2); System.out.println("str3 = " + str3); if (str2 == str3) System.out.println("The strings are equal"); else System.out.println("The strings are not equal"); } } 1. str2 and str3 should be the same. Run the program. If you did not get the expected output, find the logic error and fix it. 2. Add code to str1 and str2. If str1 comes before str2 in dictionary order, print “str1 is less than str2”; if they are same, print “Same”; otherwise, print “str1 is bigger than str2”. ****Use compareTo() method.****arrow_forward
- Code that need debugging fix with no errors // Gets a String from user // Converts the String to lowercase, and // displays the String's length // as well as a count of letters import java.util.*; public class DebugSeven4 { public static void main(String[] args) { Scanner kb = new Scanner(System.in); String aString ; int numLetters = 0; int stringLength; System.out.println("Enter a String. Include"); System.out.println("some uppercase letters, lowercase"); System.out.print("letters, and numbers >> "); aString = kb.nextLine(); stringLength = aString.length(); System.out.print("In all lowercase, the String is: "); for(int i = 0; i <= stringLength; i++) { char ch = Character.toLowerCase(aStringcharAt(i)); System.out.print(ch); if(!Character.isLetter(ch)) numLetters++; } System.out.println(); System.out.println ("The number of CHARACTERS…arrow_forward2. What is the value of x and y after executing the following program? public class MysteryNums { public static void main(String[] args) { int x = 15; sentence(x , 4); int y = x - 5; sentence(y , x ); System.out.println(x + " & " + y); } %3D %3D public static void sentence(int num1, int num2) { num1 = num1 + num2; } }arrow_forwardJAVAarrow_forward
- using System; class Program { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { Console.WriteLine(number); number = number + 2; } Random r = new Random(); int randNo= r.Next(1,88); Console.WriteLine("Random Number between 1 and 88 is "+randNo); } } how can this program be fixed to select three random numbers between 1 and 88 instead of one?arrow_forwardJAva Input. class increment { public static void main(String args[]) { double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } } Find output.arrow_forward// This program assigns values to two variables // and performs mathematical operations with them public class DebugFour1 { public static void main(String args[]) { int x = 5; int y = 8; int z = 19; System.out.println("adding " + x + y); System.out.println("subtracting " + y - z); System.out.println("dividing " + z / x); System.out.println("multiplying " + x / z); } }arrow_forward
- // Program displays some facts about a stringpublic class DebugSeven3{public static void main(String[] args){ String quote ="Honesty is the first chapter in the book of wisdom. - Thomas Jefferson"; System.out.println("index.of('f') is: " + indexOf('f'));System.out.println("index.of('x') is: " + indexOf('x'));System.out.println("char.At(5) is: " + charAt(5));System.out.println("endsWith(\"daughter\") is: " + quote.endswith("daughter"));System.out.println("endsWith(\"son\") is: " + quote.endswith("son"));System.out.println("replace('e', '*') is: " + quote.replace('e', 'M'));}}arrow_forwarddebug program please use import java.util.Scanner; // Display every character between Unicode 65 and 122 // Start new line after 20 characters public class DebugSix2 { public static void main(String args[]) { char letter; int a; final int MIN = 65; final int MAX = 122; final int NUMPERLINE = 200; final int STOPLINE1 = 0; final int STOPLINE2 = STOPLINE1 + NUMPERLINE; for(a = MIN; a <= MAX; a++) { letter = (char)a; System.out.print(" " + letter); if((a == STOPLINE1) && (a == STOPLINE) System.out.println(); } System.out.println("\nEnd of application"); } }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_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education