Question

Identify a positive value for parameter d that will cause this method to print "green", but...

Identify a positive value for parameter d that will cause this method to print "green", but not any of the other colors when executed.

   public static void ifelse(int d) {
        if (d >= 12.5) {
           System.out.println("blue");
        } else if (d % 3 == 0) {
           System.out.println("yellow");
        } else if (d < 10) {
           System.out.println("green");
        }
        if (d > 6) {
           System.out.println("red");
        }
   }
  

Homework Answers

Answer #1

Identify a positive value for parameter d that will cause this method to print "green", but not any of the other colors when executed.

   public static void ifelse(int d) {
        if (d >= 12.5) {
           System.out.println("blue");
        } else if (d % 3 == 0) {
           System.out.println("yellow");
        } else if (d < 10) {
           System.out.println("green");
        }
        if (d > 6) {
           System.out.println("red");
        }
   }
  

There will be 4 positive value for parameter d that will cause this method to print "green", but not any of the other colors when executed values are 1,2,4,5 because they are less than 12.5 and 6 and they modulo by 3 will never be zero then only one condition will be true that is d<10 and only "green" will be printed.

Make sure to hit the like button if you find this helpful for you THANK YOU AND HAPPY LEARNING!!

Know the answer?
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
Similar Questions
Which method is correct to access the value of count? public class Person { private String...
Which method is correct to access the value of count? public class Person { private String name; private int age; private static int count = 0; } A. private int getCount() {return (static)count;} B. public static int getCount() {return count;} C. public int getCount() {return static count;} D. private static int getCount() {return count;} How can you print the value of count? public class Person { private String name; private int age; private static int count=0; public Person(String a, int...
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...
Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by "seconds". End with a newline. Example output for ounces = 7: 42 seconds import java.util.Scanner; public class PopcornTimer { public void printPopcornTime(int bagOunces) { /* Your solution goes here */ } public static void main (String [] args) { PopcornTimer popcornBag = new PopcornTimer();...
Give the output of the following program. Then explain what the foo() method does, in general,...
Give the output of the following program. Then explain what the foo() method does, in general, for a given input. Is foo() a tail-recursive method? Why or why not? class SomeThing {     public static void main(String args[]) {         System.out.println(foo(6));     }     private static int foo(int input) {         if (input <= 0) {             throw new RuntimeException("invalid input");         }         else if (input == 1) {             return 1;         }         else if (input %...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Q: Implement an equals method for the ADT list that returns true when the entries in...
Q: Implement an equals method for the ADT list that returns true when the entries in one list equal the entries in a second list. In particular, add this method to the class AList. The following is the method header: public boolean equals (Object other) public class AList<T>{ private T list[]; private int capacity = 100; private int numOfEnteries =0; public AList(){ list = (T[])new Object[capacity + 1]; } public void add(T element){ numOfEnteries++; if (numOfEnteries >capacity) System.out.println ("Exceed limit");...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...