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
kondaur [170]
4 years ago
8

What is the difference between Counter Controlled iterations and Sentinel Controlled iterations? What is the purpose of the incr

ement and decrement operators? Give Examples!
Computers and Technology
1 answer:
malfutka [58]4 years ago
7 0

Answer and Explanation:

Counter-controlled loops:

In counter controlled loops, the user has an idea of how many times the loop iterates in advance.

The iterations can be counted.

so it is also called definite iterative loops.

Ex:

import java.util.Scanner;

public class Main

{

 

  public static void main(String[] args)

      {

     

          //here i is a counter variable.

          //The user knows that this for loop iterates 10 times(0 to 9 times) in advance.

          int i;

          for(i=0;i<10;i++)

              {

         

                  System.out.println("Hi! Chegg Expert");

              }

     

}

}

Sentinel-controlled loops:

Generally, loops are controlled within a definite count of executions.

But, sometimes, the user may not have a certain idea of how many times the loop needs to iterate.

then, the user needs to take the help of flag variable.

These type of loops iterate an infinite number of times.

By summarizing all the data above,

One cay says that Sentinel loops are the loops in which the user does not have any idea about how many times the body of the loop iterates in advance.

Ex:

import java.util.Scanner;

public class Main

{

 

  public static void main(String[] args)

 

      {

     

     

          int i=0;

          //here in this loop the user does not know how many times the while loop iterates.

          while(true)

               {

 

                  Scanner obj=new Scanner(System.in);

 

                  int n=obj.nextInt();

                  //it is a condition which halts the loop. 'n' is a sentinel variable.

                  if(n==2)  

                  {

                      break;

                  }

 

                  System.out.println(n);  

              }

      }

}

Increment and decrement operators:

++ are increment operators.

__ are decrement operators.

The purpose of increment and decrement operators:

When the user needs to add 1 to a variable, then the increment operator(++) is used.

When the user needs to subtract 1 from a variable, then the decrement operator(__) is used.

import java.util.Scanner;

public class Main

{

  public static void main(String[] args)

  {

     

      int i=10,j=20;

     i++;j--;

          System.out.println(i);

          System.out.println(j);

  }

}

output:

11

19

Sometimes,

these operators behaves like assignment operates since they alter the values of the variables they assigned with.

int x=1;

int y=x++;//here y is assigned to x and paralley x is

     //incremented by 1 and so y.

 

Ex:

import java.util.Scanner;

public class Main

{

  public static void main(String[] args)

  {

     

      int i=1;

          i++;

          int j=i;

          System.out.println(j);

  }

}

output:

2

     

These operators can be placed before the variable or after the variable.

If they are placed before the variable,the values changes before the evaluation of the expression happens.

If they are placed after the variable,the values changes after the evaluation of the expression happens.

ex:

import java.util.Scanner;

public class Main

{

  public static void main(String[] args)

  {

     

      int x=1;

      System.out.println(x++);

      int y=x;

      System.out.println(++y);

  }

}

You might be interested in
Readable code includes the use of
Kobotan [32]

Answer:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbbbbbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

Explanation:

7 0
3 years ago
Read 2 more answers
Lola wants to install an add-in in Excel.She has to unblock the add-in to allow Excel to open the add-in file automatically.To d
ololo11 [35]

Answer:

The correct answer is:

Properties (D)

Explanation:

First of all, option D (Properties) is the option that makes the most sense in this scenario, because the other options: Copy, Delete, and Rename are unrelated commands to what is to be achieved.

Secondly and more practically, an add-in file may not load in excel, and most of the time it is blocked by default and has to be unblocked. The following steps are used:

1. close Excel if it is open

2. open the folder where the add-in file is located, right-click on the add-in file, and select "properties"

3. a display tray will appear, having the attributes: Read-only, Hidden, Advanced, and unblock. Click the checkbox against "unblock" and make sure it is checked.

4. click Apply and Click Ok

Voila, your add-in file is unblocked.

<em>N:B The Images are for steps 2 and 3</em>

5 0
3 years ago
Write a SELECT statement that returns the category_name column from the Categories table. Return one row for each category that
KengaRu [80]

Answer:

Below is the required statement:

Explanation:

select c.categoryname

from categories c

where not exists (select 1 from products p where p.categoryid = c.categoryid);

6 0
3 years ago
Do the following SQL questions. The resulting columns must all have descriptive names. You must show the result of the query. Fo
Maslowich

Answer:

We can use CREATE command to create tables with columns having descriptive names

Explanation:

Firstly, create a table using CREATE  command in SQL. The syntax is as follows:

CREATE TABLE [table_name]

(

 [col_name] [datatype]),

[col_name] [datatype]),

[col_name] [datatype]),

[col_name] [datatype])

)

Once the table is created, we can insert the data into table using INSERT command. It's syntax is as follows:

INSERT INTO table_name VALUES('', '', '')

if datatype is string, values must be entered within single quotes. If datatype is int, values are entered directly without using  quotes.

Now, you can select the data from  the table using SELECT command. It's syntax is as follows:

SELECT column-list FROM table_name

If you want to filter rows according to conditions, you can use WHERE command.

I have created  sample table and inserted some data into it. Now, I applied some queries on it to select data from the table.

I have written in a text file and attached the same. Please find. Thank you!

Download txt
3 0
4 years ago
How do you use the Internet? Think about your typical day. When are you using the Internet? For what purposes? What role does it
gladu [14]

Answer:

I would say something like this:

I use the internet mainly for communication, school and all the necessary informations. It has become a routine thing for every person on the planet. People are able to progress in almost all spheres of life. It can link people from all over and create communities.

5 0
4 years ago
Other questions:
  • Preserving confidentiality, integrity, and availability of data is a restatement of the concern over interruption, modification,
    15·1 answer
  • Suppose company A wants to develop a program that duplicates the functionality of a programm by company B. Describe how company
    8·1 answer
  • How can the Internet help our country to be a leader in technology?
    6·1 answer
  • The most fundamental components of storage that users interact with are the:
    11·1 answer
  • Suppose we are working with an error-correcting code that will allow all single-bit errors to be corrected for memory words of l
    5·1 answer
  • A team is in the process of developing a motion picture. Currently, they are creating ideas for advertisements to make people in
    6·1 answer
  • How do you navigate multiple computer screen at one time?
    5·1 answer
  • (ACCESS 2016)
    7·2 answers
  • Rachel wants to copy eight rows of data from one spreadsheet to another. She opens the spreadsheet, highlights the appropriate d
    15·2 answers
  • Select the tasks that would be performed by an information systems graduate.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!