Question

In: Computer Science

1.        In your program, demo the split() method for strings and attach it to one of the...

1.        In your program, demo the split() method for strings and attach it to one of the buttons.

"Numbers" lesson

2.        Check if 3===3.0. Why?

3.        Find the number of zeros such that 3===3.000…01. Why can this happen?

4.    If var x=123e15, and var y=123e-15, does x===x+y? why?

5.    What is typeof NaN? Comment on its (il)logicality.

"Number Methods" lesson

6.    What is the hexadecimal number ff (written in JavaScript as 0xff) in base 10?

7.    Write all the numbers from 0 to 20 in hexadecimal form. If not sure you can always use a for loop and (if the index variable is i), print out i.toString(16).

8.    What is 0xff.toString()? Why?

9.    What is (35).toString(36)? Why?

10.    What is (35).toString(37)? Why?

11.    Give a call to alert() that gives $0.99 + 7% (sales tax, say) of $0.99.

12.    Why does (0.99+0.07*0.99).toFixed(2) give the price if it costs $0.99 + 7% sales tax?

13.    What is Number(true)?

14.    What is Number(undefined)? Why?

15.    What is parseInt(0xff)? Why?

16.    The Number entity contains useful stuff. What is the value of Number.MAX_VALUE? Is it big?

17. Consider the hexadecimal (base 16) number 9a. In a JavaScript program you would write it as: 0x9a. How would you write it in the more familiar base 10? Here is how to solve this.

a.       Recall that a "normal" base 10 number has a ones place, a tens place, a hundreds place, a thousands place, etc. Another way to put it is, it has a 100's place (100=1), a 101's (101=10), a 102's place (102=100), a 103's place (103=1,000), etc. Similarly, a base 16 number has a 160's place (160=1), a 161's (161=16), a 162's place (162=16x16=256), a 163's place (163=16x16x16=4,096), etc.

b.      So the base 16 number 9a has an "a" in the 1s place and a 9 in the 16s place.

c.       It has "a" 1s and 9 16s, so just calculate (a*1)+(9*16).

d.      What number is "a"? Well, base 10 numbers are made with 10 numeral symbols (0 1 2 3 4 5 6 8 9). Similarly, base 16 numbers are made with 16 numeral symbols (0 1 2 3 4 5 6 7 8 9 a b c d e f). An "e" for example has the value of fifteen. Base 2 numbers are made with 2 numeral symbols (0 1). Base 36 uses 36 symbols (0...9 and a...z). In everyday use we get up to base 60 (for measuring time at 60 seconds per minute, 60 minutes per hour) but rather than use 60 different symbols we use other means, as you might have noticed.

e.       You can check your answer in JavaScript using the toString() method:

var num = 128;
num.toString(16);

will provide a string for the base 10 number 128 rendered as a base 16 number. So you can see if toString() will convert your answer and give the string "9a". If it does, you got the right answer.

18.  So far we have looked at calculating a conversion from base 16 numbers into base 10. The same idea applies to converting any base into base 10. What is the base 8 number 7564 in base 10?

19.  What is the binary number 11101111 in base 10?

20.  Next, consider converting base 10 numbers into base 16 or any other base.

Calculate what the base 10 number 1000 is in base 16 (show your work, without using JavaScript). You can check your answer JavaScript using toString() if you like. Here's how to calculate it.

a.       163=4096, and there are no 4096s in 1000, so there is no fourth digit in the answer, since what you really need are the three digits for 162, 161, and 160. How many 162s are in 1000? 162=256, so the question then is how many 256s are in 1000? The answer is 3, with a remainder. So the partial answer is: 3 _ _ . Fill in the 2 blanks.

b.      The 3 is the number of 162s or 256s in 1000, which leaves 1000-3*256 = 232 unaccounted for.

c.       The next digit is for the number of 161=16s we need. We can fit 14 of them into 232: 14*16=224, with a remainder of 8 that is not yet accounted for. 14 is written "e" in base 16, so the answer so far is: 3e_ and we have one blank left to fill.

d.      The 160 or 1s place holds the number of 1s we need. 8 of them are needed to fill up the remainder of 8 that we have to deal with, so the answer is: 3e8. Thus

num = 1000;
num.toString(16);

should give the string "3e8".

21.  What is 2000 in base 16 (hexadecimal)? Calculate it without using JavaScript and show your work.

22.  Do this the fast way using toString(). What is the base 10 number 128 in base 2?

23.  Do this the fast way using toString(). What is the base 10 number 128 in base 36? toString() won't go above 36.

24.  What is 200,000,000 in hexadecimal? Do it the fast way in JavaScript unless you have a lot of extra time on your hands.

The "Random" lesson

25.  Check out https://www.w3schools.com/js/tryit.asp?filename=tryjs_random_function. Explain how it works.

26. Give a call to Math.floor() that returns a random integer from 1 to 10, inclusive (inclusive means it could return 1, 10, or any integer in between).

Solutions

Expert Solution

Dear Student ,

You have posted 26 Questions. Out of which are only allowed to answer 4 Sub Parts.

But for You I am going to answer as many as I can in the Given Time To Me .

Thank You.

1st Question to use Split Method.

2.If 3==3.0 Answer is Yes

Proof:

Question 3 Answer :.Finding the Number of Zeros will lead to infinite Loop .

Because Value of 3 does not change when there are so many zeros in between.

Question 4 Answer:

x=123e15

y=123e-15

Yes x==x+y

Proof :

Question Number 5 Answer:

The type of NaN , which stands for Not a Number is, surprisingly, a number. The reason for this is, in computing, NaN is actually technically a numeric data type. However, it is a numeric data type whose value cannot be represented using actual numbers


Related Solutions

The split method in the String class returns an array of strings consisting of the substrings...
The split method in the String class returns an array of strings consisting of the substrings split by the delimiters. However, the delimiters are not returned. Implement the following new method that returns an array of strings consisting of the substrings split by the matching delimiters, including the matching delimiters. public static String[] split(String s, String regex) For example, split("ab#12#453", "#") returns ab, #, 12, #, 453 in an array of String, and split("a?b?gf#e", "[?#]") returns a, ?, b, ?,...
please write a java code, one for method and another for the Demo to: -Compute the...
please write a java code, one for method and another for the Demo to: -Compute the average age of all female students. -Compute the least amount of credits completed among males. Store the three arrays in the demo file. Print the results within the demo file. String []gender ={"F", "F", "M", "F", "F", "M", "M", "M", "M", "F", "M", "F", "M", "F", "F", "M", "M", "F", "M", "F"}; int []age = {18, 19, 19, 21, 20, 18, 24, 19, 21,...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and your college name on the screen. √ Remember: the format of the assembly program should be like this. TITLE your title (FileName.asm) .MODEL FLAT .386 .STACK 64 .DATA str1 DB "My name: Essam Alnatsheh",13,10,'$' .CODE main PROC mov ax,@data mov ds,ax mov ah,09h mov dx, offset str1 int 21h ​mov ah,4Ch​​ ; terminate process ​mov al,0​​ ; return code ​int 21h main ENDP END...
#1    Write  a simple array program that:    Des not use an “external class & demo      program"    [If you wish, you...
#1    Write  a simple array program that:    Des not use an “external class & demo      program"    [If you wish, you may break it down into methods, but that is NOT         required.]    a.     Set up 4 arrays which each hold 6 employee’s data:              int[ ] empid              int[ ] hours              double[ ] rate              double[ ] wages          b.     Set up loops to load the empid, hours and rate arrays    c.     Set up a loop to calculate values for the wages array. TAKE OVERTIME [hours > 40],  INTO CONSIDERATION, thru the use  of...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
Write a program to print 2 strings. One string must be written by parent process and...
Write a program to print 2 strings. One string must be written by parent process and another string must be written by a child process In language C
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of...
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of strings will contain the seasons, “Winter”, “Spring”, “Summer”, and “Fall”. Your program will then contain a function that will use your seasons array to display a menu and ask the user to choose their favorite season and return that value to the main() function. Your function must include a data validation loop. The user must enter in a 1 for winter, a 2 for...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to...
Write a method that concatenates two strings passed as parameters.    Version #1 - assign to the 1st parameter the concatenation of both parameters. Perform the concatenation using the + operator. We are assuming reference parameter work that way (they don't).    Version #2 - fine. return the value of the 1st param after concatenating to it the second parameter then.    Version #3 - Let's do it the proper way now, I say. Create a temporary String reference variable...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words)...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter...
1) What's the result of calling method blitz passing strings "Aquamarine" as the first argument and...
1) What's the result of calling method blitz passing strings "Aquamarine" as the first argument and "Heliotrope" as the second argument? static int blitz(String v, String w) { if (v.length() != w.length()) return 0; int c = 0; for (int i = 0; i < v.length(); i++) if (v.charAt(i) == w.charAt(i)) c++; return c; } a)0 b)1 c)2 d) 3 2)What is NOT an advantage of dynamic arrays compared to static arrays? a)new elements can be added b)elements can be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT