MyLab Programming with Pearson eText -- Access Card -- for Starting Out with Java: Early Objects (Myprogramminglab)
6th Edition
ISBN: 9780134447179
Author: Tony Gaddis
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
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
For the program below, assume that a point on a Cartesian plane comprises values representing x and y coordinates.
The distance between two points in a Cartesian plane can be calculated using the formula derived from d=√((x2-x1)²+(y2-y1)²). Write a C++ program that prompts a user to input two points on the Cartesian plane and works out the distance between them. Use comments in your code, highlight how you have used the following concepts of C++ : class, object, constructors and destructors.
in C
For each of the following, write a single statement that performs the indicated task. Assume that long integer variables value1 and value2 have been defined and that value1 has been initialized to 200000.
a) Define the variable lPtr to be a pointer to an object of type long.
b) Assign the address of variable value1 to pointer variable lPtr.
c) Print the value of the object pointed to by lPtr.
d) Assign the value of the object pointed to by lPtr to variable value2.
e) Print the value of value2.
f) Print the address of value1.
g) Print the address stored in lPtr. Is the value printed the same as the address of value1?
Consider the following C++ code and answer the questions:
const int size=5;
int Num[size];
for (int i = 0; i < size; i++)
Num [i] = i * i + 1;
a) What is the value of *Num?
b) What is the value of *Num+1?
c) What is the value of *(Num+2)?
Chapter 2 Solutions
MyLab Programming with Pearson eText -- Access Card -- for Starting Out with Java: Early Objects (Myprogramminglab)
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 - Prob. 2.16CPCh. 2.4 - Prob. 2.17CPCh. 2.4 - Prob. 2.18CPCh. 2.4 - Prob. 2.19CPCh. 2.4 - Prob. 2.20CPCh. 2.4 - Prob. 2.21CPCh. 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 - Prob. 2.28CPCh. 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 - Prob. 2.36CPCh. 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 - Prob. 10AWCh. 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 - Prob. 3SACh. 2 - Prob. 4SACh. 2 - Prob. 5SACh. 2 - Prob. 6SACh. 2 - Prob. 7SACh. 2 - What things must be considered when deciding on a...Ch. 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 - Cookie Calories A bag of cookies holds 40 cookies....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 - Miles-per-Gallon A cars miles-per-gallon (MPG) can...Ch. 2 - Male and Female Percentages Write a program that...Ch. 2 - Test Average Write a program that asks the user to...Ch. 2 - Prob. 12PCCh. 2 - Restaurant Bill Write a program that computes the...Ch. 2 - Stock Commission Kathryn bought 1,000 shares of...Ch. 2 - Ingredient Adjuster A cookie recipe calls for the...Ch. 2 - Energy Drink Consumption A soft drink company...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
- Choose the best data type for each of the following, so that no memory storage is wasted. Give an example of a typical value that would be held by the variable, and explain why you chose the type you did. the number of years of school you have completed your final grade in this class the population of China the number of passengers on an airline flight one players score in a Scrabble game the number of Electoral College votes received by a U.S. presidential candidate the number of days with below freezing temperatures in a winter in Miami, Florida one teams score in a Major League Baseball gamearrow_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_forwardPlease code the following in Java According to the function given in code below.arrow_forward
- Complete the following questions about different types of variables:i. Check the last digit of your id number(123456789). If it is even or 0, fill the gap in (A)with the word global (i.e., static global), otherwise, fill it with local (i.e., static local).Then, complete Table I. ii. In a multi-source program, there is a fileA.c that contains variables and functions,and a fileB.c that contains the main function, as well as usage of some of theresources found in fileA.c. Explain:a) fileA.c has a global variable called my_variable, that should only beaccessed within the file. I.e., no other files should be able to access thatvariable.How should my_variable be declared inside of the file, in order to guaranteethis functionality? b) fileA.c also has a global variable called my_shared_variable, which canand should be accessible from other files, including fileB.c.How should my_shared_variable be declared in order to allow thisfunctionality?Note for item ii): You also need to state in a…arrow_forward19. In python we do not specify types,it is directly interpreted by the compiler, so consider the following operation to be performed.>>>x = 13 ? 2objective is to make sure x has a integer value, select all that apply (python 3.xx) a. x = 13 // 2 b. x = int(13 / 2) c. x = 13 % 2 d. All of the mentionedarrow_forwardint p =5 , q =6; void foo ( int b , int c ) { b = 2 * c ; p = p + c ; c = 1 + p ; q = q * 2; print ( b + c ); } main () { foo (p , q ); print p , q ; } Explain and print the output of the above code when the parameters to the foo function are passed by value. Explain and print the output of the above code when the parameters to the foo function are passed by reference. Explain and print the output of the above code when the parameters to the foo function are passed by value result. Explain and print the output of the above code when the parameters to the foo function are passed by name.arrow_forward
- 6. In Java, you have the opportunity to either use a predefined function/method or write a user-defined function/method. In this discussion, provide at least three criteria that would be used to develop an appropriate method of your choice and the rationale behind the selection of these criteria.arrow_forwardI'm working on c++ and I've been given the following instructions to modify a program: Rewrite Program 3 where the following operators are overloaded: >> << + - * == != Also overload the preincrement and postincrement operators ++ which will change the value of the complex number to its cube. I really only need help understanding the last two operators and the pre/postincrement. Here is the program I already have: #include <iostream>using namespace std; //This program uses a class to work with complex numbers // create complex number classclass ComplexNum{ //private variablesprivate: float realNum; float imaginaryNum; //public sectionpublic: //default constructor ComplexNum(float r = 0, float i = 0) :realNum(r), imaginaryNum(i) {}; //sets the complex numbers void setComplex(void) { cout << "Enter the real part: "; cin >> this->realNum; cout << "Enter the imaginary part: "; cin >>…arrow_forwardFor C++, How would I call or use a function that is passed by pointer or a reference? How would I use these in this example below? I understand how passing by value works, but when it comes to passing by references and pointers, that is when I get confused. #include <iostream> using namespace std; // passing by reference in this function void pass_ref(int &ref); // passing by pointer in this function void pass_ptr(int* ptr);arrow_forward
- Given the code below: type point real a, b end type type (point) v read*, v z=v%a/v%b print*, z end What is the equivalent code for the above statements? Question 6 options: none of the given code choices type point real a, b end type type (point), dimension(2):: v read*, v do i=1, 2 z=v(i)%a/v(i)%b end do print*, z end all the given code choices type point real a, b end type type (point), dimension(2):: v read*, v where (i>0) z=v(i)%a/v(i)%b end where print*, z end real va, vb read*, va, vb z=va/vb print*, z endarrow_forwardConsider the following JavaScript program: [5 marks]var a, b, x;function sub1() {var x, c, d;function sub2() {var a, d, e;...}...}function sub3() {var d, a, c;...} List all the variables; along with the program units where they are declared assuming dynamic scopingis used for the following sequence of callsmain calls sub2 and sub2 calls sub3 and sub3 calls sub1arrow_forwardAssume the parameters in the following code are being passed by reference. What numbers reside in the variables a and b after the swap takes place? Next, assume the parameters are being passed by value-result. What numbers reside in the variables a and b after the swap takes place this time? void swap(int x, int y, int z){ int tmp = x; x = y; y = z; z = tmp;} int main(){ int a = 3; int b = 4; swap(a, b, b);}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr