Question:
Data Types, Constants and Variables?
♪£yricảl♪
2008-05-07 07:46:24 UTC
Determine the Java data type for each of the given value.

Value: 123.456
Data type: double

[Why is it double?? How can you determine that?]

Value: "A"
Data type: String

[Why is it String? How to determine that? And, the double quotes (") enclosing the A means what? I know there will be a meaning for it but I forgot...-.-]

--------------
Write the statement to declare the variable isDone, which is of type boolean.

Ans: boolean isDone

[Hmm, can I write boolean = isDone] If cannot, what's the difference?

Write the statement to declare the variable grade, which is of type char.

Ans: Char grade;

[Is it correct? Do I have to include a semi-colon (;) at the end? If not, why? Then, do the letter 'c' in char has to be capitalised (C) or just a lowercase (c) What's the difference anyway?]

Thank you for your time. ;)
Four answers:
Lemia
2008-05-07 07:55:26 UTC
Value: 123.456

Data type: double



it is a double because it has a decimal value. it can either be a "double" or "float" value. if it is a whole number, such as "2", then the data type is "Integer"





Value: "A"

Data type: String



anything enclosed in double quotes means it is a string. so "123" would also be considered a string. a string is just text data it can consist of anything.



--------------

Write the statement to declare the variable isDone, which is of type boolean.



Ans: boolean isDone



[Hmm, can I write boolean = isDone] If cannot, what's the difference?



no you can't do that because the equal sign sets a value to a variable. you can not set a value to a data type. you must declare a variable by writing: "boolean isDone;"

a boolean can have a value of "true" or "false"



this is a declaration:

boolean isDone;



this is a definition:

boolean isDone = true;



Write the statement to declare the variable grade, which is of type char.



Ans: Char grade;



[Is it correct? Do I have to include a semi-colon (;) at the end? If not, why? Then, do the letter 'c' in char has to be capitalised (C) or just a lowercase (c) What's the difference anyway?]



it depends on which language you are using. the correct format for c++ is:

char grade;



all c and c++ statements MUST end with a semi-colon!



if this is for a test, next time do your homework and study girl! this stuff is so easy
2008-05-07 09:47:02 UTC
123.456 is type double because there's a decimal point and numbers after it.

So for example, 123 would be of type int because it is an integer.



"A" is a string because it is enclosed in quotes. This is also a string. "Math is fun sometimes."



boolean isDone means that isDone is of type boolean.

boolean = isDone won't make sense in terms of the programming language.



In your first example when you identified 123.456 as double,

you'd write it as



double 123.456;



char grade is of type char

because grade is a character

(A, B, C, D, F)



When you start programming you will have to put the semicolon at the end of type declarations.



For now, there is really no difference if the c is capital or not...

but when you begin programming you should leave it in lower case because the programming language will only identify a data type declaration when you type it out with lower case.
?
2016-10-07 12:03:10 UTC
particularly, AM's breakdown is stable, yet i'd desire to function that those are not regularly specific to one programming language. if reality be told maximum 3GL programming languages, there are continuously constants variables and documents varieties... Constants may be something that are standard, and stay fastened in the time of the existence of this technique. they are in a feeling, additionally variables, as they soak up area in reminiscence. asserting something consistent is one greater function maximum programming languages enable so as that we can keep away from the programmer from particularly changing the cost of something that would desire to stay fastened. ( pi = 3.14 would be a competent occasion of a persevering with ). Variables are something that takes up reminiscence in a application, regularly declared in improve. those can save numbers, characters, binary integers, reminiscence addresses, and so on. the type of variable this is saved in reminiscence is seen the documents type.
AnalProgrammer
2008-05-07 08:23:31 UTC
Value: 123.456

Data type: double



it is a double because it has a decimal value.

The default type for a number with a decimal point is double.

You can also specify the type as in

123.456f (float)

123.456d (double)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...