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; }}

+2
Answers (2)
  1. 11 June, 19:32
    0
    pleez answer my question too
  2. 11 June, 19:35
    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.
Know the Answer?