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
tatuchka [14]
3 years ago
5

What is the value of i after the following code is executed? int i = 1; while ( i < 10 ) { int j = 10; while ( j > i ) j--

; i += j; }
Computers and Technology
1 answer:
natka813 [3]3 years ago
3 0
<h2>The value of "i" after executing the entire code will be "16"</h2>

Explanation:

Initially the value of i will be 1. This value keeps changing after entering the while loop. Let me give you step by step result.

When i = 1, it checks whether i<10, enters the loop, initializes the "j" to 10 and again while loop runs till j>i. so before the outer while loop ends "i" is reinitialized using "i=i+j".

So When i = 1, the value of j after running inner while loop will be 1 and i will be reinitialized to 1+1 = 2, now i =2

So When i = 2,  j =2, Reinitialized value of i = 4

So When i = 4, j = 4, Reinitialized value of i = 8

So When i = 8, j = 8, Reinitialized value of i = 16.

The loop will not get executed thereafter.

You can add the below statement, after "j--;" to understand better.

cout<<"i="<<i<<"," <<"j="<<j<<"\n";

You might be interested in
HOW TO GET RID OF THESE LINES?? PLS WILL GIVE BRAINLIEST
Sladkaya [172]

Answer:

Is that your computer? Did you already try

Explanation:

  • Powering off and powering back on?
  • Or restarting it
  • It could be a school issue, like when I search something on G oogle and go to Images, it did not work and loaded very slow. But now all of a sudden, it works.
8 0
3 years ago
Read 2 more answers
How does technology improve convenience, but impact our privacy?
Aneli [31]

Answer:

Convenience of tech- Easier to shop,learn,meet new people

Impacts privacy- technology impacts your privacy because many people have their identity, credit card numbers, emails, etc.

Explanation:

~ItsOniiSama<3

Hope this helps

3 0
3 years ago
Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exac
ELEN [110]

Answer:

The program to this question can be given as:

Program:

//import package.

import java.util.*;

public class Main //defining the class

{

public static void main(String[] args) //defining main method  

{

 Scanner ob = new Scanner(System.in); //creating scanner class object.

 int[] a = new int[10];//define array.  

 int number,counts= 0,i;//define variable.

 System.out.print("Enter numbers: "); //message.

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

 {

  number=ob.nextInt();

  if (isDistinct(a,number))

  {

      a[counts] = number;//assign value in array

      counts++; // Increment count

  }

 }

 System.out.println("The distinct numbers is :" + counts);

 System.out.print("The distinct number are :");

 for (i = 0; i <a.length; i++)//loop

 {

  if (a[i] > 0)

  {

   System.out.print(" " +a[i]);//print array.    

  }

   

 }

 System.out.println();

}

public static boolean isDistinct(int[] array, int num)//defining method  

{

 for (int i = 0; i < array.length; i++)//loop for check number  

 {

  if (num == array[i]) //check condition

  {

      return false; //return value false.

  }

 }

 return true; //return value true

}

}

Output:

First time run:  

Enter ten numbers: 1 2 3 4 5 6 7 8 9 10

The number of distinct numbers is 10

The distinct numbers are 1 2 3 4 5 6 7 8 9 10

Second time run:

Enter numbers: 2 3 5 8 7 4 3 2 1 2

The distinct numbers is :7

The distinct number are : 2 3 5 8 7 4 1

Explanation:

The description of the above java code can be given as:

  • In the above java code, a class is defined that is main inside a class-main function is defined in the main function firstly creating a scanner class object that is "ob" then define variables and array that are number, counts and a[].
  • To inserts array elements we use a loop. In the loop, we use integer variable number and define a condition in if block passes a function that check value count total value.
  • In the second loop, we check the condition that array elements value is greater than 0 and print all array elements.
  • The isDistinct function checks in the array two values are not the same. if the values are the same it will return false value because this function is the boolean type that returns an only boolean value.
6 0
3 years ago
Where can i make a 3d animation for free ( pls don't trick me)
Vinvika [58]

Answer:

I don't know if it would work for what you need but you could try scratch. (sorry if this isn't what you needed.)

4 0
3 years ago
First write a method to calculate the greatest common divisor (GCD) of two positive integers using Euclid’s algorithm (also know
MAVERICK [17]

Answer:

import java.util.Scanner;

public class Gcd

{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Enter two numbers to find their GCD: ");

 int number1 = input.nextInt();

 int number2 = input.nextInt();

 

 if(number1 > 0 && number2 > 0)

     System.out.println("GCD of " + number1 +" and " + number2 +" is: " + findGCD(number1, number2));

       else

           System.out.println("Invalid Input!");

}  

public static int findGCD(int number1, int number2) {

    if(number2 == 0){

        return number1;

    }

return findGCD(number2, number1 % number2);

}

}

Explanation:

To be able to find GCD, we need to factorize the numbers and multiply common factors.

- <u>Inside the function:</u>

- Recursively divide <em>number1</em> by <em>number2</em> until <em>number2</em> is equal to zero.

- Return <em>number1</em>  when the <em>number2</em> is equal to zero. That means we found all the divisors of <em>number1</em>

- <u>Inside the main:</u>

- Ask user to input numbers

- Check if both numbers are greater than zero

- If they satisfy the condition, call the method and print the result.

7 0
3 years ago
Other questions:
  • True or false? It is just too challenging to have different password for every
    12·1 answer
  • The analog signals that carry analog or digital data comprise composites built from combinations of simple sine waves.
    12·1 answer
  • Binary code what does this mean I was sick so I don't under stand
    7·2 answers
  • Write a C++ program that prompt the user to enter v in meter/second(m/s) and the acceleration in a in meters/second squared (m/s
    15·1 answer
  • When creating a chart or graph, which should be completed first?
    9·2 answers
  • About how long did it take to photograph Daguerre's photograph of the street?
    7·1 answer
  • Technologies can offer safety and protection for people
    11·1 answer
  • Part 1: For this assignment, call it assign0 Implement the following library and driver program under assign0: Your library will
    5·1 answer
  • write a pay-raise program that requests a person's first name, last name, and current annual salary, and then displays the perso
    6·1 answer
  • A. Get a value for x from the user.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!