Question

In: Computer Science

java code Question 2: What are the type and value of each of the expressions below?...

java code

Question 2: What are the type and value of each of the expressions below?

int [] numbers = { 3, 6, 15, 22, 100, 0 };

double [] decimals = { 3.5, 4.5, 2.0, 2.0, 2.0 };

String [] words = {"alpha", "beta", "gamma"};

  1. numbers[3] + numbers[2]

  1. decimals[2] - decimals[0] + numbers[4]

  1. words[1].charAt( numbers [0] )

  1. numbers[4] * decimals[1] <= numbers[5] * numbers[0]

Solutions

Expert Solution

There are a total of 4 expressions which are -

1) numbers[3] + numbers[2]

Now since numbers is of integer type hence any operation on it will remains the same type. So the type of this expression is integer or int.

Now since index starts from 0 so,

Numbers[3] wil be 22 and numbers[2] will be 12 os the output will be -

22 +12 = 34

2) decimals[2] - decimals[0] + numbers[4]

As explained in the above part its data type will also be same. The type will be double. The output of expression will be -

2.0 - 3.5 +2.0 = 0.5

3) words[1].charAt( numbers [0] )

The type of this will be string. The output of. Numbers[0] will be 3 so the equation will become -

words[1].charAt(3) now words[1] is equal to beta. So the equation will be -

'beta'. CharAt(3)= a. - #the character at 3rd index.

4) numbers[4] * decimals[1] <= numbers[5] * numbers[0]

The type of this expression will be boolean as it'll return either true or false. As its a comparison.

The values of variables are -

Numbers[4] =100

Numbers[5] = 0

Numbers[0] =3

Decimals[1] = 4.5

So the equation will be as -

100*4.5 <= 0*3. - - > 450 <= 0

Which is false as 450 > 0. So the answer will be false.

​​​


Related Solutions

Write in Java. Separate code for each question. The answer to the first question should NOT...
Write in Java. Separate code for each question. The answer to the first question should NOT be comparable. 1. Write a class to represent a AlternativeEnergyCar. Select the fields and methods that fit the modeling of an alternative energy car. Make sure to include code for the constructors, set/get methods, a toString() method. 2. Inheritance – Create two abstract subclasses of AECar, one for Electric cars and one for Altfuel cars. Next create four additional subclasses., two for types of...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
Java question - How can the code below be modified to accept multi digit input. String...
Java question - How can the code below be modified to accept multi digit input. String e = "1+9+8"; int r = e.charAt(0)-'0'; for (int i = 1; i < e.length(); i+=2){    if (e.charAt(i) == '+'){ r += e.charAt(i+1)-'0'; } else{ r -= e.charAt(i+1)-'0'; } The only built in String methods that can be used are lowercase(), length(), and charAt(). Arrays and parseInt() cannot be used. So we want to know how we can get an answer if a...
X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the...
X86 Assembly MASM Questions below ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;; Answer each question below by writing code at the APPROPRIATE places at the end ;;;;; of the file as indicated. ;;;;; Q2: Write the directive to bring in the IO library           ;;;;; Q3: Create a constant called DAYS_PER_WEEK and initialize it to 5 ;;;;;     Create a constant called WEEKS_PER_YEAR and initialize it to 49 ;;;;; Q4: Create a constant called DAYS_PER_YEAR by using DAYS_PER_WEEK and ;;;;;     WEEKS_PER_YEAR (of Q3) in an...
Question: How can the code below be implemented in java? TreapNode* deleteNode(TreapNode* root, int key) {...
Question: How can the code below be implemented in java? TreapNode* deleteNode(TreapNode* root, int key) {     // Base case     if (root == NULL) return root;        // IF KEYS IS NOT AT ROOT     if (key < root->key)         root->left = deleteNode(root->left, key);     else if (key > root->key)         root->right = deleteNode(root->right, key);        // IF KEY IS AT ROOT        // If left is NULL     else if (root->left == NULL)     {         TreapNode *temp = root->right;         delete(root);         root = temp; // Make right...
I need java code for this ..thx Question 2 Credit card numbers are not completely random...
I need java code for this ..thx Question 2 Credit card numbers are not completely random sequences; they follow certain rules depending on the card issuer. A MasterCard number must meet these criteria: • Begin with 51, 52, 53, 54, 55, or something in the range 222100-272099 • 16 digits in length • Satisfy the Luhn formula, created by IBM scientist Hans Peter Luhn in the 1950s Here’s how the Luhn formula works: Double every other digit going backwards, starting...
Determine the value, true or false, of each of the following Boolean expressions, assuming that the...
Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10. Give your answer as one of the values true or false. a. (count == 0) && (limit < 20) b. count == 0 && limit < 20 c. (limit > 20) || (count < 5) d. !(count == 12) e. (count == 1) && (x < y) f....
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT