Question

4. Write an if/else statement in ternary format that compares the value of two int variables,...

4. Write an if/else statement in ternary format that compares the value of two int variables, firstNum and secondNum, and sets the value of an int variable minValue appropriately as follows: minValue should be the minimum of firstNum and secondNum.

5. Assume that Person is a predefined class and that the declaration Person[] people; has already been performed. Then the instruction

People = new Person [200];

Reserves memory space for(Circle the answer):

     Option 1: a single Person object

     Option 2: 200 Person objects

     Option 3: a single reference variable that points to a single Person object

     Option 4:200 reference variables and 200 Person objects

     Option 5: 200 reference variable, each of which can point to a separate Person object

     Option 6: a single reference variable to the memory that stores all 200 Person objects

6. Consider a method defined as follows:

Public void myMethod(double x, int y):

Circle which of the following method calls is legal? (zero, one, or more answers may be correct)

     Option 1: myMethod();

     Option 2: myMethod(-1);

     Option 3: myMethod(7 * 3.0, 7 /14);

     Option 4: myMethod(37, 0.5);

7. Given two String variables, string1 and string2, write a line of code that would determine if they have the same length

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 4:

Answer : minValue=(firstNum>secondNum)?secondNum:firstNum;

Explanation :Below screen shows the Java code for ternary operator.

Main.java 2 public class Main public static void main(String[] args) //declaring variables int firstNum-2, secondNum-1,minVal

*****************************

Question 6:

Answer : Option 3: myMethod(7 * 3.0, 7 /14);

Explanation :for myMethod(double,int) which calls myMethod(7 * 3.0, 7 /14);

*****************************

Question 7:

Explanation :Below code snippet gives the details

public class Main
{
   public static void main(String[] args) {
   //declaring strings
   String string1="asdf",string2="pqrs";
   //checking strings
   if(string1.length()==string2.length())
   {
   System.out.println("Equal");//display equal
   }
   else{
   System.out.println("Not Equal");//display not equal
   }
   }
}

Output :

Main.java 1 public class Main public static void main(String[] args) 4. //declaring strings String string1-asdf, string2-p

*****************************

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
4. Write an if/else statement in ternary format that compares the value of two int variables,...
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
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