Write a program segment that simulates flipping a coin 25 times by generating and displaying 25 random integers, each of which is either 1 or 2

Answers

Answer 1
Answer:

Answer:

//import the Random class

import java.util.Random;

//Begin class definition

public class CoinFlipper {

   //The main method

    public static void main(String []args){

       

       //Create an object of the Random class

       Random ran = new Random();

       System.out.println("Result");    

       //Use the object and the number of times for simulation

       //to call the flipCoin method

       flipCoin(ran, 25);

    } //End of main method

   

   

    //Method to flip coin

    public static void flipCoin(Random ran, int nooftimes){

        //Create a loop to run as many times as specified in variable nooftimes

       for(int i=1; i<=nooftimes; i++)

           System.out.println(ran.nextInt(2) + 1);

    }

}   //End of class definition

====================================================

Sample Output:

Result

1

1

1

2

1

2

2

1

2

1

1

2

1

2

1

1

1

2

1

1

1

2

2

1

2

========================================================

Explanation:

The above code has been written in Java. It contains comments explaining every part of the code. Please go through the comments.

The sample output from the execution of the code is also given above.

The code is re-written as follows without comments.

import java.util.Random;

public class CoinFlipper {

    public static void main(String []args){

       Random ran = new Random();

       System.out.println("Result");    

       flipCoin(ran, 25);

    }

   

    public static void flipCoin(Random ran, int nooftimes){

       for(int i=1; i<=nooftimes; i++)

           System.out.println(ran.nextInt(2) + 1);

    }

}


Related Questions

Subtract (100000)2 from (111)2 using 1s and 2s complement method of subtraction​
Factory Design Pattern Assignment This assignment will give you practice in using the Factory/Abstract Factory Design Pattern. You are going to create a Terraforming program. What does terraform mean
/* Q1. (20 points)Create a stored procedure sp_Q1 that takes two country names like 'Japan' or 'USA'as two inputs and returns two independent sets of rows: (1) all suppliers in the input countries, and (2) products supplied by these suppliers. The returned suppliers should contain SupplierID, CompanyName, Phone, and Country. The returned products require their ProductID, ProductName, UnitPrice, SupplierID, and must sorted by SupplierID.You should include 'go' to indicate the end of script that creates the procedure and you must include a simple testing script to call your sp_Q1 using 'UK' and 'Canada' as its two inputs\.\**For your reference only: A sample solution shows this procedure can be created in11 to 13 lines of code. Depending on logic and implementation or coding style, yoursolution could be shorter or longer\.\*/
99 POINTS HELP ASAP PLEASE!!!Select the mathematical statement that is true. A.22 % 2 > −3 B.22 % 2 < 5 C.22 % 2 == 4 D.22 % 2 != 1This is for my python coding class thank you
Raj, a recent graduate, has recently joined your organization as a Junior Business Analyst. He has been asked to conduct a Feasibility Analysis on whether to automate the process of software installation or not. If you were in Raj's place, based on which of these parameters would you identify if that process can be automated? Pick onea. Availability of software licensingb. Entering license number during installationc. Operating System being usedd. Software version being used

codes with three characters are included in the icd-10-cm as the heading of a of codes that may be further subdivided by the use of 4th, 5th, or 6th characters, which provide greater detail.

Answers

The icd-10-cm includes codes with three characters as the header of a group of codes that may be further split by the use of four, five, or six characters; this is known as the level of detailing in coding.

What does coding actually mean?

Describe coding. Coding, often known as computer programming, is how we communicate with computers. Because coding gives instructions to a machine, it is comparable to writing a set of rules. By learning to write code, you can tell machines much more quickly what to do or how to act.

What three forms of coding are there?

Languages written in an imperative, functional, logical, or object-oriented style are common. These coding language paradigms are available for programmers to select from in order to best meet their demands for a given project.

To know more about coding visit:

brainly.com/question/17204194

#SPJ4

Where does execution resume after an exception has been thrown and caught?

Answers

Answer:

The execution resumes in the finally block if one exists or otherwise from the next statement following the try...catch block.

Explanation:

Once an exception has been thrown and caught in the code, the execution continues with the statements in the finally block if one exists. If there is no finally block defined then execution resumes from the next statement following the try... catch block. For example:

try{

//An exception is raised

}

catch (Exception e){

//Exception is handled

}

System.out.println("After try...catch");

In this code segment, the next statement to be executed after catch is the System.out.println();

PLEASE HELP!!!For this activity, you will create two designs for the same project. For example, you might choose to create a CD cover for your favorite band’s newest release, or you might want to design a menu for the local deli. No matter what you decide for your subject matter, the two designs must involve different media. One of these media will be an image-editing program, such as Inkscape. You will learn more about the basic tools available in Inkscape later in this lesson. The two designs should incorporate different techniques. For example, you might make one design abstract, while making the other more realistic. Be sure to save both of your designs. Scan or take a picture of the design that wasn’t created in an image-editing program. You will submit this item later in this lesson as your portfolio item. Select the link to access the Techniques Activity Rubric.

Answers

Answer:

I'm not exactly sure on what the question is, but from reading it, I determined that you'll be creating 2 different designs using Inkscape/Photoshop. I'm leaving 2 of my designs in here for you to use on your project. Unknown on what to do about the design that wasn't created in an image-editing program.

Which of these terms best describes the type of AI used in today’s email spam filters, speech recognition, and other specific applications?A. Artificial Narrow Intelligence (ANI)
B. Artificial General Intelligence (AGI)

Answers

The term that is described in the question is A. Artificial Narrow Intelligence.

Artificial intelligence simply means the ability of a computer system to automatically make decisions based on the input value received.

Artificial Narrow Intelligence is the computer's ability to do a single task well. It's used in today’s email spam filters, speech recognition, and other specific applications.

Read related link on:

brainly.com/question/16439202

Answer:

A. Artificial Narrow Intelligence.

Explanation:

Artificial intelligence is the ability of a computer system, with the help of programming, automatically make decisions as humanly as possible, based on the input value received. There are three types of artificial intelligence, namely, artificial narrow intelligence (ANI), artificial general intelligence (AGI) and artificial super intelligence (ASI).

ANI is focus on executing one specific task extremely well like web crawler, speech recognition, email spam filters etc. AGI is meant to handle human intellectual task, while ASI performs task beyond human intellect.

I'm stuck on this Java exercise problem and don't know how to organize my code with proper formatting and it's not helping that I'm pretty terrible at logic. I can't figure out how to return the number of spaces to be displayed in the main method.

Answers

In your "count spaces method" before the for loop, you want to declare an int variable (let's call it spc)

then, each time you find that charat, spc++.


also, the string must be declared in the main method, not the spaces count method.


The actual code:


public class CountSpaces{

public static void main(String[] args){

String instring = "(your quote here)";

int spaces = calculateSpaces(instring);

System.out.println("The number of spaces is " + spaces);

}

public static int calculateSpaces(String in){

int spc = 0;

for(int i= 0; i<in.length; i++){

if(in.charAt(i)== ' '){

spc++;

}

}

return spc;

}

}


that should be it.  If you have any questions, feel free to reach out.

In which situation does a linear search always perform better than a binary search?

Answers

Answer:

Linear search can be suitable for searching over an unsorted array. whereas, Elements in the array need to be in sorted order for binary search. The binary search algorithm uses the divide-and-conquer approach, it does not scan every element in the list. Hence, It is the best search algorithm

pls mrk me brainliest