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
OLga [1]
3 years ago
13

What does the following code segment do?

Computers and Technology
1 answer:
vampirchik [111]3 years ago
4 0

Answer:

Hi!

var count =0;  <em>//initialize count.</em>

var sevens =0 ;  <em>//initialize sevens.</em>

while(count<100)  <em>// loops while count is minor than 100. *counts never add 1 at the final of the loop, so this while is always true. </em>

{

<em>//Math.floor(x) round to the max Integer a number. Example : 45.90 -> 46.</em>

<em>//Math.random() returns a number between [0, 1).</em>

var roll1 = Math.floor(Math.random()*6+1);   <em>//Gets a integer using Math.random(), adds 1, and round it withMath.floor() then saves in roll1.</em>

var roll2 = Math.floor(Math.random()*6+1);  <em>//Gets a integer using Math.random(), adds 1, and round it withMath.floor() then saves in roll2.</em>

if(roll1 + roll2 == 7) <em> //If the sum of roll1 and roll2 is 7 adds 1 to sevens.</em>

sevens = sevens +1;  

}

<em>//*count is not incremented, so while(count<100) -> always true.</em>

You might be interested in
Among the second generation home console companies,which managed to come out on top
crimeas [40]

Answer:

The second generation of home consoles occurred from (1976-1988) at this time the most popular and consoled regarded as best was the Atari 2600

Explanation:

answer from Cligon768 on this site

3 0
4 years ago
Create a function void process(char ch, int x, int y)- to accept an arithmetic operator (+,-./, in argum
saul85 [17]

Answer:

The program is as follows:

import java.util.*;

public class Main{

   public static void process(char ch, int x, int y){

if(ch == '+'){

    System.out.print(x+y);  }

else if(ch == '-'){

    System.out.print(x-y);  }

else if(ch == '*'){

    System.out.print(x*y);  }

else if(ch == '/'){

    if(y!=0){

        double num = x;

        System.out.print(num/y);      }

    else{

        System.out.print("Cannot divide by 0");     } }

else{

    System.out.print("Invalid operator"); }

 }

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int x, y;

 char ch;

 System.out.print("Enter two integers: ");

 x = input.nextInt(); y = input.nextInt();

 System.out.print("Enter operator: ");

 ch = input.next().charAt(0);  

 process(ch,x, y);

}

}

Explanation:

The function begins here

   public static void process(char ch, int x, int y){

If the character is +, this prints the sum of both integers

<em> if(ch == '+'){</em>

<em>     System.out.print(x+y);  }</em>

If the character is -, this prints the difference of both integers

<em> else if(ch == '-'){</em>

<em>     System.out.print(x-y);  }</em>

If the character is *, this prints the product of both integers

<em> else if(ch == '*'){</em>

<em>     System.out.print(x*y);  }</em>

If the character is /, this prints the division of both integers.

<em> else if(ch == '/'){</em>

<em>     if(y!=0){</em>

<em>         double num = x;</em>

<em>         System.out.print(num/y);      }</em>

<em>     else{</em>

<em>This is executed if the denominator is 0</em>

<em>         System.out.print("Cannot divide by 0");     } }</em>

Invalid operator is printed for every other character

<em>else{</em>

<em>     System.out.print("Invalid operator"); }</em>

<em> </em> }

The main begins here

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

This declares both integers

 int x, y;

This declares the operator

 char ch;

Get input for both integers

<em>  System.out.print("Enter two integers: ");</em>

<em>  x = input.nextInt(); y = input.nextInt();</em>

Get input for the operator

<em>  System.out.print("Enter operator: ");</em>

<em>  ch = input.next().charAt(0);   </em>

Call the function

 process(ch,x, y);

}

}

6 0
3 years ago
Write a recursive function, displayFiles, that expects a pathname as an argument. The path name can be either the name of a file
Virty [35]

The following code will be used to write a recursive function and display files

<u>Explanation:</u>

#Import required packages

import os

#Define recursive function

#displayFiles() has a single argument

#which may be either pathname or filename

def displayFiles(pathname):

   #if the given argument is pathname for directory

   if (os.path.isdir(pathname)):

       #open the directory

       for item in os.listdir(pathname):

           #append items in the list

           newItem = os.path.join(pathname, item)

           #print each filename

           #call the function recursively

           displayFiles(newItem)    

   #otherwise if the pathname

   #is filename

   else:

       #set the pathname to filename

       filename=pathname

       baseFile = os.path.basename(filename)

       print("File Name: ", baseFile)

       #open the file in read mode

       with open(filename, "r") as file:

           print("Content:")

           #display the contents of the file

           for line in file:

               #print line

               print(line)

           print()

8 0
3 years ago
Aight Ik this aint an assignment question but I just need to vent
eduard

Answer:

Your everything

Explanation:

That's your friends opinion that your "ugly" nothing will hurt it you don't take it to the heart. Don't be sorry, if they were truly your friend they wouldn't have said those. Your good yourself you don't have to have to have someone say you are good. You are good as yourself. Don't change, for anyone. Your beautiful. :) <33

4 0
3 years ago
Camila wanted to increase the readability of her company newsletter. To do this, she added _____.
inysia [295]
Lots of white spaces
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which best describes a paraphrase?
    13·1 answer
  • In microsoft what displays when the mouse pointer rests on selected text or data that can be formatted.
    8·1 answer
  • Write a method called all Less that accepts two arrays of integers and returns true if each element in the first array is less t
    12·1 answer
  • can you give me a tip to fix my SIM card becuaus when i put it on my phone it has no signal , can anyone fix this , thank you.​
    9·2 answers
  • As each layer of the OSI model adds its encapsulation header and/or footer, the ______ gets larger until it reaches the physical
    8·1 answer
  • Write a program that implements a class called Dog that contains instance data that represent the dog's name and age. • define t
    10·1 answer
  • Which statement best describes an advantage of using the Subtotal dialog box?
    14·1 answer
  • Submit your business presentation that clearly compares and contrasts three different cell phone service plans. I have TO HAVE I
    14·1 answer
  • Can someone please do this java lab for me (100 point version)?
    9·1 answer
  • Who played Anne in the green gables??
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!