This site requires JavaScript, please enable it in your browser!
Greenfoot back
Ticker175
Ticker175 wrote ...

2018/5/11

java and pseudocode Declaration

Ticker175 Ticker175

2018/5/11

#
Hey guys i need some help with the theory elements of the java coding language and pseudocode documentation i need to write the theory for declaring the following (in both java and pseudocode): Java Pseudocode Integer int initialize/input String string String Floating point/real ??? ??? Boolean true / false true / false One-dimensional array ??? ???
danpost danpost

2018/5/11

#
Ticker175 wrote...
i need to write the theory for declaring the following (in both java and pseudocode)
What exactly do you mean by "write a theory for declaring" Types in java and pseudocode? If your table is something to be completed, I am a bit confused with the "initialize/input" entry, in that it does not seem to match up with the rest of the table. Please explain exactly what you are after. Also, the Java column is a mix of things -- 'int' is a primitive type; 'string' has no meaning in java; and 'true' and 'false' are boolean values. The Pseudocode column is similarly mixed up, making it difficult to understand what you are after.
Ticker175 Ticker175

2018/5/13

#
sorry for the late response I've been very busy =/ i should have phrased myself better i meant how would you implement the following in a theoretical application (a universal answer) Eg. To declare an integer in java/greenfoot you would type
1
int
but if you were declaring an integer in pseudocode you would type
1
initialise
or
1
input
sorry for the confusion i mainly just wanted someone to check that what i have is correct. and to get help with floating points and one-dimentional arrays
danpost danpost

2018/5/13

#
Ticker175 wrote...
i should have phrased myself better i meant how would you implement the following in a theoretical application (a universal answer) Eg. To declare an integer in java/greenfoot you would type
1
int
but if you were declaring an integer in pseudocode you would type
1
initialize
or
1
input
sorry for the confusion i mainly just wanted someone to check that what i have is correct. and to get help with floating points and one-dimentional arrays
Pseudo-code can be really anything that shows the sequence of steps that the actual code might take. It is a non-syntactical, unruly representation. As per your example, "initialize an integer variable" could be used to represent a line beginning with "int" in java. "declare" is also a perfectly fine word to use. "input", on the other hand, is usually used for data that is being read in from an outside source (i.e.. typed in or read from a file) and probably is not a good word for initialize or declare. I think the following might be what you are looking for:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int i = 0; // initialize an integer variable with a value of zero
Integer n = new Integer(0); // initialize a new Integer object set to zero
 
String string = "ABC"; // declare a String object containing the character string "ABC"
char[] charArray = string.toCharArray(); // represent the string as a char array
String string2 = new String(charArray); // create a String object that represents the char array
 
float value = 0f; // assign a new float variable called "value" an initial value of zero
Float floatValue = new Float(value); // create a Float object and assign it the previous float value
// also known as wrapping the value in an object
 
boolean condition = true; // initialize a new boolean set to true
 
int[] intArray; // declare an integer array called "array" (default value is "null")
intArray = new int[] { 0, 1, 2, 3, 4 }; // assign to the integer array variable a new int array containing the first five whole numbers
 
String[] stringArray = new String[5]; // initialize a new String array of length 5 (array is not "null", but elements are)
Please note that "true", "false" and "null" are values, not types. Also, realize that "int", "float" and "boolean" are primitive types and not objects, while "Integer", "String" and arrays are objects. "Integer" is a wrapper class for a primitive int value. All primitive types have a wrapper class (Integer, Boolean, Float, Byte, Character, Short, Long and Double). "String" is an object that contains an array of characters. As shown, they can easily be converted to and from a char array object. Objects that wrap primitive types can never be "null", while all others, including array can be. Hope this clears things up a bit.
Ticker175 Ticker175

2018/5/14

#
That's exactly what i was looking for thanks for the help =)
You need to login to post a reply.