Ask Question

Click run to compile and execute, and note the incorrect program output. Fix the bug in theprogram. public class BeansInJars {public static void main (String [] args) {int numBeans = 500; int numJars = 3; int totalBeans = 0; System. out. print (numBeans + " beans in "); System. out. print (numJars + " jars yields "); totalBeans = numBeans * numJars; System. out. println ("totalBeans" + " total"); return; }}

+5
Answers (2)
  1. 29 April, 01:54
    0
    The output of the given incorrect program as follows:

    Output:

    500 beans in 3 jars yields totalBeans total

    Explanation:

    The correct program to this question as follows:

    Program:

    //defining class

    public class Main / /class-name BeansInJars

    {

    //Declaring main method

    public static void main (String a[]) / /main method

    {

    int numBeans = 500, numJars = 3, totalBeans = 0; / /defining integer variables and assigning value

    //use of print function

    System. out. print (numBeans); / /print values

    System. out. print (" beans in "); //print message

    System. out. print (numJars); / /print values

    System. out. print (" jars yields "); //print message

    totalBeans = numBeans * numJars; / /calculating multiplication

    System. out. print (totalBeans); / /print values

    System. out. print (" total"); //print message

    }

    }

    Output:

    500 beans in 1500 total

    Explanation of the above program as follows:

    In the above java program, a class that is " BeansInJars" is declared inside the class the main method is defined, which contains three integer variables, which are "numBeans, numJars, and totalBeans". In these variables, a value is assigned, that is "500, 3, and 0", and the third variable is used first two variables to calculate their multiplication. Inside the main method, the print function is used, which prints the first variable value then message and then multiplication.
  2. 29 April, 01:55
    0
    pleez answer my question too
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Click run to compile and execute, and note the incorrect program output. Fix the bug in theprogram. public class BeansInJars {public static ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers