1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
fenix001 [56]
4 years ago
5

What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 15) { sum = sum + i; i++; } System.out

.println("The value of sum is " + sum);
Computers and Technology
1 answer:
Marianna [84]4 years ago
4 0

Answer:

The value of sum is 120

Explanation:

Consider the same code snippet numbered below:

  1.        int i   =    1;
  2.        int sum = 0;
  3.        while (i <= 15) {
  4.            sum = sum + i;
  5.            i++;
  6.        }
  7.        System.out.println("The value of sum is " + sum);
  8.    }

Line 1 Initializes an int variable i to 1

Line 2 creates another int variable sum, sets it to 0

line 3 has a while statement that executes until i becomes equal to 15

In line 4 the current value of sum is continuously added to i as long as the condition in line 3 stays true.

Line 5 ensures there is no infinite loop by increasing i by 1

At line 7 The value of the variable sum will be 120. This is the sum of numbers from 1 to 15. and it is printed to the console.

You might be interested in
When computing the cost of the basket of goods and services purchased by a typical consumer, which of the following changes from
Free_Kalibri [48]

Answer:

the prices of the goods and services

Explanation:

Under normal circumstances, the relative prices of goods and services in an economy are constantly changing, since they are set depending on the quantity demanded and offered in the market where they are traded, and if they are seasonal.

Suppose an umbrella costs one hundred pesos and a two hundred shirt. This means that the shirt is worth twice the umbrella. In the rainy season, people will buy more umbrellas, so it will increase its price, becoming more expensive in relation to the beach shirt. The only thing that changed was the relative price between both products, given the increase in the demand for umbrellas. Therefore, the price of one good only makes sense in relation to the price of another and not by itself.

Another reason is when the prices of almost all goods and services rise and continue to increase due to an increase in the amount of money in circulation. This is because people have more money to spend and will demand more products, and if the amount of goods and services in the market is the same, prices will continue to rise, since the amount offered has not increased for supply the increase in demand.

3 0
3 years ago
HURRY!!!!!!!!!!!!!
Anna35 [415]

Answer:

You make use of a scale (See Explanation)

Explanation:

Given

Length = 12 feet

Required

How would you represent this on drawing.

Knowing that a length of 12 feet can't be drawn on drawing, the best way to do this is to make use of a scale measurement.

The scale to use depends on you and the size of paper at your disposal.

Assume you adopt a scale of 1 inch: 1 feet

This means that a length of 12 feet will be represented by 12 inches in drawings

7 0
3 years ago
This is the thing that I don't understand why did they banned private chat like there are long-distance relationships, and frien
zavuch27 [327]

Answer:

lil

Explanation:

7 0
3 years ago
Read 2 more answers
Write a program that prompts the user to enter the year and the first three letters of a month name (with the first letter in up
elena55 [62]

Answer:

I am writing a C++ program.

#include <iostream> // for input output functions

using namespace std; // to identify objects like cout, cin

int main() { // start of main() function body

   int year; // stores the year entered

   string month;  // holds the letters of a month

   cout<<"Enter the Year: "; // prompts user to enter year

   cin>>year; // reads year entered by user

   cout<<"Enter first three letters of a month ";

// prompts user to enter first three letters of a month

   cin>>month;    //reads the three letters of month entered by the user

// formula to determine leap year

   bool leapYear =((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);

//if checks if the 3 letters of input month match with one from these months  

if ( month == "Jan" || month =="Mar" || month == "May" || month == "Jul" || month == "Aug"|| month == "Oct"|| month == "Dec")

 //displays no of days in input month and year are 31

 cout<<"Number of days in "<<month<<" "<<year<<": 31 ";

//else- if checks if the input month matches with one from these months

else if (month =="Apr" || month=="Jun"|| month == "Sep"|| month == "Nov")

 //displays no of days in input month and year are 31

       cout<<"Number of days in "<<month<<" "<<year<<": 30 ";

else if (month =="Feb") //if the input month is Feb

cout<<"Number of days in "<<month<<" "<<year<<": "<<((leapYear) ? 29 : 28); // checks if the year is leap if yes then displays 29 days else 28

else //if none of the above if else conditions is true

{cout<<"Not a valid entry"; //displays invalid entry

    exit(0); //exits the program } }

             

Explanation:

The basic working of this program is briefly described in the comments above. I will explain the logic of the program.

This program takes int type year and a string month from the user (first three letters of the month).

Then it computes that if the year entered by the user is a leap year by this formula:

((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)

A leap year has 366 days and year which is not a leap year has 365 days. modulus operator is used here which returns the remainder of the division. If the input year is completely divisible by 4 which means we get remainder 0 then mod of year is taken with 100.  If the input year is evenly divisible by 100 then mode of year is taken with 400. Then if the input year is completely divisible by 400 this means the year is a leap year. Otherwise, year is not a leap year.

Next the IF statement is used to check the condition if the first three letters the month entered by the user matches one of the those mentioned in the if statement. As we know that the months Jan, March, May, July, Aug, Oct and Dec have 31 days so if the input month is any of these months then the message is displayed that the month has 31 days.

If the input month is not from the above months then else-if part is checked for input month. If the input month's letters matches with any of the months in else-if condition then the message displayed that the input year and month has 30 days.

If the above if and else if statement evaluate to false then the second else-if part is executed which checks if the input month is Feb, if its true the conditional statement checks if the input year is a leap year or not. If the input year is a leap year then the month Feb has 29 days otherwise 28 days.

If none of the above conditions are true this means that the user might be entering wrong letters such as Fab or Aig etc instead of Feb or Aug, so the message printed : Not a valid entry and program exits.

Screenshot of program along with its output is attached.

5 0
4 years ago
A group consists of 10 kids and 2 adults. On a hike, they must form a line with an adult at the front and an adult at the back.
blsea [12.9K]

Answer:

b. 2.9!

Explanation:

There are is a mistake in the question.

Suppose the group consist of 10 kids and 2 adults, the number of ways in which they can form the line is:

= 2! 10!

= 2× 1× 10!

= 2.10!

But since that is not in the given option.

Let assume that the group consists of 9 kids and 2 adults, the number of ways in which they can form the line is:

No of ways the kids can be permutated =  9 ways

No of ways the adult can be permutated  = two ways.

Thus; the number of ways in which they can form the line = 2! 9!

= 2 × 1× 9!

= 2.9!

6 0
3 years ago
Other questions:
  • Create a new file that contains a summary of the total consumption for three sectors: "Residential," "Commercial," and "Industri
    10·1 answer
  • You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips
    10·2 answers
  • What is the approximate area of the figure? A. 129 square inches B. 113 square inches C. 110 square inches D. 44 square inches
    15·1 answer
  • Write a program with a loop that lets the user enter a series of positive integers. The user should enter −1 to signal the end o
    7·1 answer
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • Please help. 15 points!!!!
    8·2 answers
  • "A user reports that the corporate web server cannot be accessed. A technician verifies that the web server can be accessed by i
    8·1 answer
  • Which method is used for resolving data dependency conflict by the compiler itself?
    6·1 answer
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    8·1 answer
  • Political parties to address the interest of civil society<br>​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!