Question

1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat&#...

1. What is the output?

System.out.print(3 + 3 * 3);

a.

18

b.

12

c.

9

d.

0

e.

10

            2.   What is output by the code below?

System.out.print("\\dog\\cat");

a.

dog

b.

dogcat

c.

\\dog\\cat

d.

\dog\cat

e.

catdog\\\\

            3.   What is returned by the call     getIt(9) ?

public static int getIt(int num){

int ans = 0;

if( num >=2 )

{

     if( num >= 7)

        ans += 2;

     else

        ans += 3;

}

ans += 4;

return ans;

}

a.

4

b.

2

c.

6

d.

7

e.

9

            4.   What is returned by the call     getIt(3) ?

public static int getIt(int num)

{

int ans = 0;

if( num >=2 )

{

     if( num >= 7)

        ans += 2;

     else

        ans += 3;

}

ans += 4;

return ans;

}

a.

4

b.

6

c.

7

d.

4

e.

9

            5.   What is returned by the call     getIt(1) ?

public static int getIt(int num)

{

int ans = 0;

if( num >=2 )

{

     if( num >= 7)

        ans += 2;

}

else

{

     ans += 3;

}

   ans += 4;

return ans;

}

a.

4

b.

5

c.

6

d.

7

e.

9

              

            6.   What is output by the code below?

//client code

int[] list = {2,12,11,45,52,36,5,3,1};

System.out.println( go(list) );

//go receives an array and returns a calculated value

public static double go( int[] ray )

{

int val = 0;

for(int i=0; i < ray.length; i = i + 2)

    val = val + ray[i];

return val;

}

a.

45.0

b.

96.0

c.

56.0

d.

65.0

e.

71.0

            7.   What is output by the code below?

//client code

int[] list = {2,12,11,45,52,36};

System.out.println( go(list) );

//go receives an array and returns a calculated value

public static int go( int[] ray )

{

int val = Integer.MIN_VALUE;

for(int i=0; i < ray.length; i++)

    if( ray[i] > val )

      val = ray[i];

return val;

}

a.

45

b.

2

c.

12

d.

52

e.

36

              

            8.   What is the code shown below working to locate?

public static int go( int[] ray )

{

int val = Integer.MIN_VALUE;

for(int i=0; i < ray.length; i++)

    if( ray[i] > val )

      val = ray[i];

return val;

}

a.

The code is trying to locate all of the even numbers.

b.

The code is trying to locate the biggest number.

c.

The code is trying to locate the smallest number.

d.

The code is trying to locate all of the odd numbers.

e.

The code is trying to locate the biggest even number.

            9.   What is output by the code below?

//client code

int[] list = {3, 6, 9, 2, 4, 5};

System.out.println( go(list) );

//go receives an array and returns a calculated value

public static int go( int[] ray )

{

int val = 0;

for(int i=0; i < ray.length; i++)

    val = val + ray[i];

return val;

}

a.

29

b.

27

c.

20

d.

26

e.

25

          10.   What is output by the code below?

System.out.println(Math.pow(2,4));

a.

32

b.

16

c.

16.0

d.

32.0

e.

8.0

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

ANSWER:-

QUESTION (1):-

OPTION (B) 12

QUESTION (2):-

OPTION (D) \dog\cat


QUESTION (3):-

OPTION (C) 6

QUESTION (4):-

OPTION (E) 71.0

QUESTION (5):-

OPTION (D) 52

QUESTION (6):-

OPTION (B)

QUESTION (7):-

OPTION (A) 29

QUESTION (8):-

OPTION (C) 16.0

Add a comment
Know the answer?
Add Answer to:
1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10             2.   What is output by the code below? System.out.print("\\dog\\cat&#...
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
  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at...

    I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at all, it is just left blank. package edu.wit.cs.comp1050; /** * Solution to the third programming assignment * When it runs it outputs the amount in quarters, dimes, nickels and pennies * * @author Rose Levine * */ import java.util.Scanner; public class PA1c {       /**    * Error message to display for negative amount    */    public static final String ERR_MSG =...

  • Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1));...

    Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1)); foo3(s.substring(0, s.length() -1)); } } What is the output of: foo3(“”); 2, You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n) //line 9 { if (n = = 0)    return 1; else    System.out.println(n* foo(n-1) ); }                                    //line 15 At compile time, you get the following error: Text.java: 15: missing return statement }                                ...

  • java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then...

    java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> {    LinkedList<T> list;       public Stack() {        list = new LinkedList<T>();    }       public boolean isEmpty() {        return list.isEmpty();   ...

  • Please try to explain the answers as well. It will be highly appreciated. Output of the...

    Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32)                 num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test {   ...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • c++ Consider the following C++ code: 7 string animals[5] = {"dog", "cat", "turkey", "shark", "lion"); B...

    c++ Consider the following C++ code: 7 string animals[5] = {"dog", "cat", "turkey", "shark", "lion"); B 9 void* printword(void* arg) 10 { 11 int id = *((int*) arg); 12 13 cout << "Current word: « animals[id] << endl; 15 pthread_exit(NULL); 16 } 17 18 int main() 19 { 20 pthread_t thread_id[5]; 21 22 for(int num = 0; num < 5; num++) 23 { 24 1/ pass the current value of id as a parameter to the new thread 25 pthread_create(&thread_id(num),...

  • Given the following Java code fragment, what is output? int a, b; String c, d, e;...

    Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String(“I LOVE”); String y = “java!”; a = x.length( ); System.out.println(“1) “ + a); b = y.length( ); System.out.println(“2) “ + b); c = y.toUpperCase( ); System.out.println(“3) “ + c); d = x.toLowerCase( ); System.out.println(“4) “ + d); e = x.concat(y); System.out.println(“5) “ + e);

  • Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time...

    Doubly Linked List The assignment is to modify the below code in any way (like changing the method of a function). Time complexity is omitted. Any methods/functions below could be changed into something different. I was thinking of changing the method of getting size of list and maybe change from numbers to letters for nodes. import java.util.Scanner; /* Class Node */ class Node { protected int data; protected Node next, prev; /* Constructor */ public Node() { next = null;...

  • Consider the encryption code  Encryption Code true false - stringContains is an encryption algorithm that can be...

    Consider the encryption code  Encryption Code true false - stringContains is an encryption algorithm that can be decrpyted true false - Running reverseString twice will have no effect true false - Running incLetters(s,4) then incLetters(s,-4) will have no effect true false - using maxDigit as an encryption algorighm, it can be decrypted USE CODE BELOW: package encryption; import java.util.Scanner; public class Encryption { public static void main(String[] args) { Scanner scanner = new Scanner (System.in); String password, encryptedPassword, salt; int increment;...

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