Question

I had a few questions in Computer Science (Java).

I got these questions wrong and I would like the CORRECT answer and an EXPLANATION PLEASE.

Please use the correct number when giving the answer such as

1a:.

1b:

etc

1. For Each of the following Bits of code enter the final value of the variable names ans. a. int x = 23; int y = 7; Int ans

3. Write some code using println statement to reproduce the following output: a. He said coding is fun and we all agreed. M

5. Consider the code snippet below. In the blank below enter the final value of variable named x. a. int x = 2; switch(x) {

7. Write the declaration of a for loop that begins its counter at 10 and counts down to 0. Note that the declaration is just

9. Consider the code below. Enter in the final contents of the array with brackets at the beginning and end, and the values i

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1a)x%y % operator calculates the remainder of the expression
23%7 (7*3=21)23-21 =2 is the remainder
1b)x/y gives the quotient of the expression As both x and y are integers it returns int only
42/10=4 and 42%5(5*8=40) =4
4+2 =6

1c)

(y*y)+z = (12*12)+13=144+13=157
y+z=12+13=25
157/25 = 6 (it gives int because both are integers)

1d)

sqrt gives square root of number
4+2^3 = 4 + 64 =68
ans=68/12.5 =5.44
2)

if(a<b)
{
  
}
else if(a==b)
{
  
}
else if(a>b)
{
  
}

3)

System.out.println("He said \"coding is fun\" and we all agreed.");

4)int x=rand.nextInt(-50,50)

5)

Because it will consider all cases from 2 to 5 and default because no break statement is there

x=2*2*2=8
case 3:x=8+8=16
case 4:x=16=16+16=48
case 5:x=48*5=240
default x=1

atlast x becomes 1

6)Here also x will be 1 becase no break is there

7)Your answer is correct bt you gave 'o' instead of 0

for(int i=10;i>=0;i--)

8)

Same qestion as above

for(int i=10;i>=0;i--)

9)

It will calculate 2*i*i =2*0*0

3*i=3*0=0

0+0+10=10

for second 2*1*1+3*1+10=15

2*2*2+3*2+10=24

2*3*3+3*3+10=37

[10,15,24,37]

comment if any doubts

Add a comment
Know the answer?
Add Answer to:
I had a few questions in Computer Science (Java). I got these questions wrong and I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

    Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1)        a.) [1, 2, 2, 2]        b.) [1, 1, 1, 2]        c.) [1, 2, 1, 2]        d.) [1,...

  • I am trying to make a word guessing game on java, where there are four letters...

    I am trying to make a word guessing game on java, where there are four letters and you have 10 guesses to try and guess the letter combination. When I try to play, it says every combination of letters I enter is correct. For example: "You have 10 guesses left. Enter your guess: wxyz There are 4 correct letter placements. Congrats!" I emailed my professor and she said one of my methods is wrong because I'm only checking for specific...

  • It's been too long since I have done any Java programming. Can anyone help me with...

    It's been too long since I have done any Java programming. Can anyone help me with this one? Thank you 6.5 Write the declaration for a class named C that declares: (1) a private int instance variable named mX; (2) a private int class variable named mY initialized to 0; (3) a private int class constant named A which is equivalent to 100; (4) a public int class constant named B which is equivalent to 200; (5) public accessor and...

  • Problems 9-35 odd numbers only(9,11,13,15 …35) k newNum numi (int) (4.6/2)1 . Do a walk-through to...

    Problems 9-35 odd numbers only(9,11,13,15 …35) k newNum numi (int) (4.6/2)1 . Do a walk-through to find the value assigned to e. Assume that all variables are properly declared. a -31 es" (a%b) * 6; e-(a b+ d)/ 4 10. Which of the following variable declarations are correct? If'a variable declaration is not correct, give the reasoníy) and provide the correct variable declaration. n = 12; char letter int one = 5, two; //Line 3 double x, Y zi //tine...

  • home / study / engineering / computer science / computer science questions and answers / in...

    home / study / engineering / computer science / computer science questions and answers / in basic c please with comments so i can redo it on my own, thank you! for this lab, you only ... Question: In basic C please with comments so I can redo It on my own, thank you! For this lab, you only nee... In basic C please with comments so I can redo It on my own, thank you! For this lab, you...

  • The following are three questions on a practice examination for Computer Science 102. I need help...

    The following are three questions on a practice examination for Computer Science 102. I need help not only getting the answer but i need careful explanations and work shown for each of the three problems because some of these are "trick" questions: SHOW YOUR WORK AND LOGIC ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 point What is printed to the screen with the code below? int main double a -5/2; cout << a; Type your answer... 23 1 point Given the following code...

  • Please answer both questions thank you. Question 49 (1 point) What is wrong with the following...

    Please answer both questions thank you. Question 49 (1 point) What is wrong with the following code snippet? for (int i 1; i <= 5; i++) { int squared = i + i; System.out.println(i + IT "! squared = + squared); } System.out.println("Last square = " + squared); calculation error variable scope error O nothing incorrect use of for loop Question 47 (1 point) What are the values of num1 and num2 and result after the execution of mystery (num1,...

  • Java Questions When creating a for loop, which statement will correctly initialize more than one variable?...

    Java Questions When creating a for loop, which statement will correctly initialize more than one variable? a. for a=1, b=2 c. for(a=1, b=2) b. for(a=1; b=2) d. for(a = 1&& b = 2) A method employee() is returning a double value. Which of the following is the correct way of defining this method? public double employee()                                    c. public int employee() public double employee(int t)                  d. public void employee() The ____ statement is useful when you need to test a...

  • Write simplistic recursive Java code for Sierpinski I made a psuedo code tell me if anything...

    Write simplistic recursive Java code for Sierpinski I made a psuedo code tell me if anything wrong with it: // x - left edge, y - right edge, z - peak, num - number of times the program is supposed to run public void drawTriangle (int x, int y, int z, int num) maketriangle(x,y,z); //imaginary method to create triangle using coordinates. if (num == 0) { return; } else { int midxy = (y-x)/2; int midxz = (z-x)/2; int midyz...

  • Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class...

    Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT