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

In java. Determine the value of each of the following expressions. (Format your answer with two...
In java. Determine the value of each of the following expressions. (Format your answer with two decimal places.) a. Math.abs(-4) b. Math.abs(10.8) c. Math.abs(-2.5) d. Math.pow(3.2, 2) e. Math.pow(2.5, 3) f. Math.sqrt(25.0) g. Math.sqrt(6.25) h. Math.pow(3.0, 4.0) / Math.abs(-9) i. Math.floor(28.95) j. Math.ceil(35.2)
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 the question about the java and please show the detail comment and code of each...
This the question about the java and please show the detail comment and code of each class.Thank you. And the "+" means "public" the "-" means "private" and testBankAccount(): void testMobilePhone(): void testChocolate(): void all are static Create four classes with the following UML diagrams: +-----------------------------+ | BankAccount | +-----------------------------+ | - money: int | +-----------------------------+ | + BankAccount(int money) | | + getMoney(): int | | + setMoney(int money): void | | + testBankAccount(): void | +-----------------------------+ +------------------------------------------------+ |...
Write a java code that takes 2 parameters input and output and and guesses value of...
Write a java code that takes 2 parameters input and output and and guesses value of 3 variables x,y,z for following equation: output/input = (x)/(y*z) and range of x = 2 to 512 and y and z = 2 to 32 for example public int method(int input, int output) and input was 10 and output was 80 it'll return x=32 and y=2 and z=2.
Java question: I need to fix a point class (code below) Thank you! /** * A...
Java question: I need to fix a point class (code below) Thank you! /** * A point, implemented as a location without a shape. */ public class Point extends Location { // TODO your job // HINT: use a circle with radius 0 as the shape! public Point(final int x, final int y) { super(-1, -1, null); assert x >= 0; assert y >= 0; } }
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;...
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...
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...
using Java progam Q1: What will be the value of x after the following code is...
using Java progam Q1: What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 100; } Q2: What will be the value of x after the following statements are executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; } Q3: What is the output of the following progm? public static void main(String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT