Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 2.4, Problem 2.14CP
Program Plan Intro
Data types to be used for a variable:
A memory space, which contains a data value, is called as variable.
- The variable must be declared before it is used in the program, because Java
programming language statically typed. - The declaration of variable tells the compiler about the type of data to be stored in it along with the variable name.
- The datatype is a set of values and each datatype have its own purpose.
- Based on the input value, datatypes are assigned to the variable.
- Datatype can be int, short, byte, double, float, long, Boolean, and String.
- “int”, “short” and “byte” datatype is used for values containing integers and natural numbers.
- “double” and “float” datatype are used for values with decimal numbers.
- “String” datatype is used for values containing alphanumeric characters.
- “Boolean” datatype is used for values containing 0 or 1 and True or False.
Explanation of Solution
b. Primitive data type used to store whole number in the region of -40,000 to +40,000:
The Primitive data type, which is used to store whole number in the r...
Explanation of Solution
c. The literal that uses more memory:
“22.1” and “22.1F” are the two given literals.
The literal, which occupies more memory is “22.1”, because, “22.1” is a double variable and “22...
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
In java code NOT c or C++
Write a complete C++ program that
asks the user to input information
for at least 10 students.
Use structure for the information
below:
Name of the student, Matric No,
Course No, Obtained Marks
rogr
The program should then display
the information based upon marks
in ascending and descending order.
To solve ascending and descending
order the program should have two
functions that have an array of
structure as a parameter and the
functions should be called from the
main function.
Solve this in C++
Chapter 2 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 2.1 - Prob. 2.1CPCh. 2.1 - When the program in Question 2.1 is saved to a...Ch. 2.1 - Complete the following program skeleton so it...Ch. 2.1 - On paper, write a program that will display your...Ch. 2.1 - Prob. 2.5CPCh. 2.1 - Every Java application program must have...Ch. 2.2 - The following program will not compile because the...Ch. 2.2 - Study the following program and show what it will...Ch. 2.2 - On paper, write a program that will display your...Ch. 2.3 - Examine the following program. // This program...
Ch. 2.3 - What will the following program display on the...Ch. 2.4 - Which of the following are illegal variable names...Ch. 2.4 - Prob. 2.13CPCh. 2.4 - Prob. 2.14CPCh. 2.4 - Prob. 2.15CPCh. 2.4 - A program declares a float variable named number,...Ch. 2.4 - Prob. 2.17CPCh. 2.4 - Prob. 2.18CPCh. 2.4 - Prob. 2.19CPCh. 2.4 - Prob. 2.20CPCh. 2.4 - What is wrong with the following statement? char...Ch. 2.5 - Prob. 2.22CPCh. 2.5 - Prob. 2.23CPCh. 2.6 - Write statements using combined assignment...Ch. 2.7 - The following declaration appears in a program:...Ch. 2.7 - The variable a is a float and the variable b is a...Ch. 2.9 - Write a statement that declares a String variable...Ch. 2.9 - Assume that stringLength is an int variable. Write...Ch. 2.9 - Prob. 2.29CPCh. 2.9 - Prob. 2.30CPCh. 2.9 - Prob. 2.31CPCh. 2.11 - Prob. 2.32CPCh. 2.11 - How are documentation comments different from...Ch. 2.14 - Prob. 2.34CPCh. 2.14 - Write code that will display each of the dialog...Ch. 2.14 - Write code that displays an input dialog asking...Ch. 2.14 - Prob. 2.37CPCh. 2 - Every complete statement ends with a __________....Ch. 2 - The following data 72 'A' Hello World 2.8712 are...Ch. 2 - A group of statements, such as the contents of a...Ch. 2 - Which of the following are not valid assignment...Ch. 2 - Which of the following are nor valid println...Ch. 2 - The negation operator is __________. a. unary b....Ch. 2 - This key word is used to declare a named constant....Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - These characters mark the beginning of a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - Which Scanner class method would you use to read a...Ch. 2 - You can use this class to display dialog boxes. a....Ch. 2 - Prob. 14MCCh. 2 - Prob. 15MCCh. 2 - True or False: A left brace in a Java program is...Ch. 2 - True or False: A variable must be declared before...Ch. 2 - True or False: Variable names may begin with a...Ch. 2 - True or False: You cannot change the value of a...Ch. 2 - True or False: Comments that begin with / / can be...Ch. 2 - True or False: If one of an operators operands is...Ch. 2 - What will the following code segments print on the...Ch. 2 - int x = 0, y=2; x = y 4; System.out.println(x +...Ch. 2 - System.out.print(I am the incredible);...Ch. 2 - System.out.print(Be careful\n);...Ch. 2 - int a, x = 23; a = x % 2; System.out.println(x +...Ch. 2 - Find the Error There are a number of syntax errors...Ch. 2 - Show how the double variables temp, weight, and...Ch. 2 - Prob. 2AWCh. 2 - Write assignment statements that perform the...Ch. 2 - Assume the variables result, w, x, y, and z are...Ch. 2 - Prob. 5AWCh. 2 - Modify the following program so it prints two...Ch. 2 - What will the following code output? int apples =...Ch. 2 - What will the following code output? double d =...Ch. 2 - What will the following code output? String...Ch. 2 - What will the following code output? String...Ch. 2 - Convert the following pseudocode to Java code. Be...Ch. 2 - Prob. 12AWCh. 2 - Write the code to set up all the necessary objects...Ch. 2 - Prob. 14AWCh. 2 - A program has a float variable named total and a...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Is the following comment a single-line style...Ch. 2 - Describe what the phrase self-documenting program...Ch. 2 - Prob. 4SACh. 2 - Prob. 5SACh. 2 - Prob. 6SACh. 2 - Prob. 7SACh. 2 - Prob. 8SACh. 2 - Briefly describe the difference between variable...Ch. 2 - What is the difference between comments that start...Ch. 2 - Briefly describe what programming style means. Why...Ch. 2 - Assume that a program uses the named constant PI...Ch. 2 - Assume the file Sales Average, java is a Java...Ch. 2 - Prob. 14SACh. 2 - Name, Age, and Annual Income Write a program that...Ch. 2 - Name and Initials Write a program that has the...Ch. 2 - Personal Information Write a program that displays...Ch. 2 - Star Pattern Write a program that displays the...Ch. 2 - Sales Prediction The East Coast sales division of...Ch. 2 - Land Calculation One acre of land is equivalent to...Ch. 2 - Sales Tax Write a program that will ask the user...Ch. 2 - Cookie Calories A bag of cookies holds 40 cookies....Ch. 2 - Miles-per-Gallon A cars miles-per-gallon (MPG) can...Ch. 2 - Test Average Write a program that asks the user to...Ch. 2 - Circuit Board Profit An electronics company sells...Ch. 2 - Prob. 12PCCh. 2 - Restaurant Bill Write a program that computes the...Ch. 2 - Male and Female Percentages Write a program that...Ch. 2 - Stock Commission Kathryn bought 600 shares of...Ch. 2 - Energy Drink Consumption A soft drink company...Ch. 2 - Ingredient Adjuster A cookie recipe calls for the...Ch. 2 - Word Game Write a program that plays a word game...Ch. 2 - Stock Transaction Program Last month Joe purchased...Ch. 2 - Planting Grapevines A vineyard owner is planting...Ch. 2 - Compound Interest When a bank account pays...
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
- Pls make a code for this on c++ and make sure it is 100% correct. i wastred 4 questoins on this and they all are not correct. Write the code as described in the questions below. Submit your code electronically in the box at the bottom. You may only use Java, C# or C++. The economy is defined using a 2-dimensional data structure: A “payday” will be considered to be any region of $ values where all cells in the region are connected either vertically or horizontally. For example, the following illustrates a matrix with 5 rows and 8 columns containing three objects. $’s and P are used in the diagram to represent the two types of values: PPPP$PPPPPP$$PPPPP$$PPP$PP$PPPP$P$PPP$$$ a) Write a program to read in the data from the text file and store it into a data structure. Your program should output it to the screen after it has read in the file. (If you can’t get this to work hard-code the above example and continue to part b). Here is a sample text file (containing the above data):…arrow_forwardExercise 10 Automatic type conversion is called coercion. For example, if an int variable and a float variable are added in Java, the value of the int variable is coerced to float and a floating-point add is done. True or Falsearrow_forward1. In using scanf the reference to data was always passed. When using printf the reference was passed for a string, but the data value was required for types such as integer. This says that what is commonly refer to as a variable actually has 3 parts: 1 - The label (sometimes called the id or name); 2 - the reference; 3 - the value. Explain to the best of your understanding what is the difference between each of these three parts, and how it changes the cognitive model or metaphor you use to understand a variable. The type of the variable (how the variable is stored and operations on the variable) are associated with what part of the variable, the label, reference, or value? 2. Which parts of the variable exist at compile time, and which parts exist at run time? 3. Harder question with more insight: Can a value be a reference? Can you think of an example? (Think of structs and arrays). 4. Even harder, this is a real world example. I read that Python has immutable primitive types (e.g.…arrow_forward
- Write a program that computes the number of extraterrestrial civilizations capable of communicating with us. - The program should use the following as constants in accordance with Drake's calculations: R. = 1, f = 1, f₁ =1 - The program should prompt the user for the values of every other variable and store those variables as a data-type that makes sense given the type of information that the variable represents. - The program should compute the number of civilizations, N, and write this value to the console window.arrow_forwardUse C language in creating this programarrow_forwardYou are assigned to develop a C++ Program using Classes, Functions, Arrays and Pointers that requires users to enter their own passwords. Your software requires that user’s passwords meet the following criteria: The password should be at least sixteen (16) characters long. The password should contain at least: one uppercase letter one lowercase letter one digit one special character (no spaces) Write a program that asks for a password and then verifies that it meets the stated criteria. If it doesn’t, the program should display a message telling the user why. Whenever possible, use pointers. Manually destroy any memory used when finished using it.arrow_forward
- Note: Please answer in C++ Programming language. During Eid, it is a tradition for every father to give his children money to spend on entertainment. Chef has N coins; denote the value of the coin i by vi. Since today is Eid, Chef gives one coin to each of his two children. He wants the absolute value of the difference between the values of the coins given to the two children to be as small as possible to be as fair as possible. Help the chef by telling him the minimum possible difference between the values of the coins given to the two children. Of course, the chef cannot give the same coin to both children. Possible input 1 3 142 Required Output 1arrow_forwardIn this exercise, you will be writing a C++ program that displays the grade earned for given score of a subject. You will be using an Object-Oriented Programming (OOP) approach to write the program. Notes: Write the program in a single source code file and use the inline style to define the class. That means, the definition of each method is written directly in the class declaration. • Follow proper naming convention: o Use camel Case to name functions, methods, and variables. ▪ Example: int calculateTotal(), int thisIsVariable O Use Pascal Case to name class and data type. Example: class Student { } o Use CAPITAL case to all characters to name constants. ▪ Example: const int MAXIMUM_STUDENT = 10; o Use small case to all characters to name a file ■ Example: my_main_program.cpp Modify the starter program provided (main.cpp) to accomplish the following tasks: 1. Declare a class to model subject information which consists of three attributes, the subject's name, code, and the score earned…arrow_forwardTrying to write a gravity function in C languagearrow_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