Question

What is wrong with the following statement? How could you correct it? if(payRate < 5.85 &&...

  1. What is wrong with the following statement? How could you correct it?

if(payRate < 5.85 && payRate > 60)

                   System.out.println("Error in pay rate");

  1. while(10 > 1){

    System.out.println("This prints forever.");

        }

Identify the problem that exists in the above while loop.

  1. What is the keyword break for? What is the keyword continue for? Will the following programs terminate? If so, give the output.
    a.) int balance =
    1. 10; while (true) {
    2.    if (balance < 9)
    3.       break;
    4. balance = balance - 9;

}

System.out.println("Balance is " + balance);

  1. b.) int balance = 10;

while (true) {

                if (balance < 9)  

            continue;

                        balance = balance - 9;

}

System.out.println("Balance is " + balance);

4. Making a comparison to 0 is slower than making a comparison to any other value.

  a. True b. False

5. How many times will outputLabel be called?

for(int customer = 1; customer <= 20; ++customer)     

for(int color = 1; color <= 3; ++color)        

   outputLabel();

                   a. 0            b. 3

  1. 20            d. 60

Homework Answers

Answer #1

1

&& condition check the both condition here suppose pay rate is 10 then first is false and secnnd is true but overall is false so statement inside the if will not execute s use or condition

if(payRate < 5.85 || payRate > 60)

                   System.out.println("Error in pay rate");

2

while(10 > 1){

    System.out.println("This prints forever.");

        }

here while is always true so it will execute infinite time.

3

break :- it is used to come out the loop of parent

continue:- when continue word get execute it will jump to next iteration without executing below of the statement

a) Balance is 1

b)basically it will show error that unreachable statement

4

false

5 d) 60

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
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);...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { //...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { // Scanner class object declare Scanner readStudentFile = null; // try block begin /*System.out.println("Working Directory = " + System.getProperty("user.dir")); // for debugging purposes only*/ try { // open file readStudentFile = new Scanner(new File("student.txt")); // loop until end of file while (readStudentFile.hasNextLine()) { String stu = readStudentFile.nextLine(); String[] eachStu; eachStu = stu.split(" "); String firstName = null, middleName = null, lastName = null; long id...
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....
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
I have run huge piece of code. I need a UML for it. I dont what...
I have run huge piece of code. I need a UML for it. I dont what a UML is, but my professor said he needs it. Please help. Thanks. import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.Scanner; public class CreditCardValidation { private String inputFileName; private String outputValidCardFileName; private String outputInvalidCardFileName; public static void main(String[] args) { CreditCardValidation ccValidationObj = new CreditCardValidation(); ccValidationObj.readFile(); } //Deafult Constrictor to inilialize instance variable public CreditCardValidation () { this.inputFileName = "data.txt"; this.outputValidCardFileName =...
While exploring MBA programs, a student gathered the following information. What kind of relationship exists between...
While exploring MBA programs, a student gathered the following information. What kind of relationship exists between variables and how can this information be used in decision making (i.e. what data would you gather on other schools as you continue your search) University Salary Rank Tuition GMAT Group Group 1 Group 2 Group 3 1 $105,100 2.8 $72,693 695 1 1 0 0 2 $115,478 3.2 $80,486 708 1 1 0 0 3 $112,318 3.2 $77,003 706 1 1 0 0...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT