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
elena-14-01-66 [18.8K]
3 years ago
11

Please help with coding assignment.

Computers and Technology
1 answer:
Inessa05 [86]3 years ago
4 0

Answer:

import java.util.Random;

class Main {

   

   public int stopAtFive (int j) {

      Random rand = new Random();

      int number = 0;

      for(int i=0; i<j; i++) {

          number = rand.nextInt(9)+1;

          System.out.println(number);

          if (number == 5) {

              System.out.println();

              break;

          }

      }

      return number;

   }

   

   public static void main(String args[]) {

       Main main = new Main();

       main.stopAtFive(20);

       main.stopAtFive(20);

   }

}

Explanation:

Your requirements do not say what has to be displayed or returned from the method, but you can use this as a starting point.

You might be interested in
create your own min function that finds the minimum element in a list and use it in a separate function
schepotkina [342]

Answer:

def minfunction(mylist):

   min = mylist[0]

   for i in mylist:

       if i < min:

           min = i

   print("The minimum is: "+str(min))

   

def anotherfunction():

   mylist = []

   n = int(input("Length of list: "))

   for i in range(n):

       listelement = int(input(": "))

       mylist.append(listelement)

   minfunction(mylist)

   

anotherfunction()

Explanation:

This solution is implemented in Python

This defines the min function

def minfunction(mylist):

This initializes the minimum element to the first index element

   min = mylist[0]

This iterates through the list

   for i in mylist:

This checks for the minimum

       if i < min:

... and assigns the minimum to variable min

           min = i

This prints the minimum element

   print("The minimum is: "+str(min))

   

This defines a separate function. This  separate function is used to input items into the list

def anotherfunction():

This defines an empty list

   mylist = []

This prompts user for length of list

   n = int(input("Length of list: "))

The following iteration inputs elements into the list

<em>    for i in range(n):</em>

<em>        listelement = int(input(": "))</em>

<em>        mylist.append(listelement)</em>

This calls the minimum function

   minfunction(mylist)

   

The main starts here and this calls the separate function

anotherfunction()

5 0
3 years ago
Which class members should be declared as public?
yawa3891 [41]

Answer:

B. Methods and occasionally final attributes

Explanation:

In Computer programming, class members can be defined as the members of a class that typically represents or indicates the behavior and data contained in a class.

Basically, the members of a class are declared in a class, as well as all classes in its inheritance hierarchy except for destructors and constructors.

In a class, member variables are mainly known as its attributes while its member function are seldomly referred to as its methods or behaviors.

One of the main benefits and importance of using classes is that classes helps to protect and safely guard their member variables and methods by controlling access from other objects.

Therefore, the class members which should be declared as public are methods and occasionally final attributes because a public access modifier can be accessed from anywhere such as within the current or external assembly, as there are no restrictions on its access.

6 0
3 years ago
Which process alters readable data into unreadable form to prevent unauthorized access known as?
EleoNora [17]
Encryption. Using a secret key, the data is encrypted. To decrypt it, the same or a different key is needed. Unauthorised entities should not have such a key.
3 0
4 years ago
What is the purpose of a budget
Iteru [2.4K]
To one say money, and two to have pocket money. If you are on a budget which is when you can spend X amount of money. Then you would be able to pay bills and not go over your budget or you  will not have money for Bills and car notes and insurance, stuff like that.

3 0
3 years ago
Please help me with my question ​
Ahat [919]

Answer:

1. Template

2. Name of the website

3. Signature of the instructor

3 0
3 years ago
Read 2 more answers
Other questions:
  • Out of the following guidlines which should you use when writing a memo?
    10·2 answers
  • What is the only real language a computer understands?
    8·1 answer
  • While you work on the customer’s printer, he continues chatting about his network and problems he’s been experiencing. One compl
    14·2 answers
  • Use the Bisection Method to find the root 2. Write a main program and a function program 3. Main Program a. define constants b.
    9·1 answer
  • What happens if you try to compile and run this program?
    5·1 answer
  • Discuss, in brief thedifferent variations of BLAST. (Maximum 5 innumber)
    10·1 answer
  • Identifying How to Print a Record on One Page
    5·1 answer
  • Make a presentation on ms word
    6·2 answers
  • 1. Assume that in an implementation of the RSA cryptosystem one modular squar- ing takes 75% of the time of a modular multiplica
    15·1 answer
  • In which directory would a system administrator store scripts that should be run monthly by the cron daemon?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!