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
bekas [8.4K]
3 years ago
6

Write a function called activity which takes an integer parameter X that does the following:

Computers and Technology
1 answer:
vodomira [7]3 years ago
8 0

Answer:

here is code in java.

import java.util.*;

class Main

{

//  main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // Scanner class object to read the input integer

       Scanner scr=new Scanner(System.in);

       // ask user to enter the input

       System.out.print("enter a number:");

       // read the input

       int x=scr.nextInt();

       // call the function with parameter "x"

       activity(x);

       

   }catch(Exception ex){

       return;}

}

// activity function to perform given tasks

public static void activity(int x)

{

    // print all the Numbers from 1 to x

    System.out.print("Numbers:");

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

    {

        System.out.print(i+" ");

    }

     System.out.println();

    // print all the Evens from 1 to x

     System.out.print("Evens:");

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

    {

        if(i%2==0)

        System.out.print(i+" ");

    }

     System.out.println();

     // replace divisible of 5 and 7 with "fiver" and "ssss"

     System.out.print("Activity:");

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

    {

        if(i%5==0)

        System.out.print("fiver ");

        else if(i%7==0)

        System.out.print("ssss ");

        else

        System.out.print(i+" ");

    }    

}

}

Explanation:

Read an integer with the help of Scanner class object and assign it to variable "x". Call the function activity() with parameter "x". In the activity function, first print "Numbers" followed by all numbers from 1 to X. Then print header "Evens" followed by all the even number from 1 to x. In last print "Activity" header followed by numbers from 1 to x and replace a number with "fiver" if it is divisible by 5 or replace with "ssss" if it  divisible by 7.

Output:

enter a number:17                                                                                                          

Numbers:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                                                                          

Evens:2 4 6 8 10 12 14 16                                                                                                  

Activity:1 2 3 4 fiver 6 ssss 8 9 fiver 11 12 13 ssss fiver 16 17  

You might be interested in
A positive integer is called a perfect number if it is equal to the sum of all of its positive divisors, excluding itself. For e
Ad libitum [116K]

i = 1

while i < 10001:

   total = 0

   x = 1

   while x < i:

       if i % x == 0:

           total += x

       x+=1

   if total == i:

       print(str(i)+" is a perfect number")

   i += 1

When you run this code, you'll see that 6, 28, 496, and 8128 are all perfect numbers.

5 0
3 years ago
A company's ____________ is the percentage of the total target market for the product that belongs to the company.
grigory [225]

a companys Market share is the percentage of the total target market for the product that belongs to the company

3 0
3 years ago
What is a cpu and what does it do
Nuetrik [128]
The CPU is the brain of a computer, containing all the circuitry needed to process input, store data, and output results. The CPU is constantly following instructions of computer programs that tell it which data to process and how to process it.
7 0
2 years ago
Read 2 more answers
Which of these is NOT an advantage of the impact of computer careers.
Volgvan
2nd choice, "An increase in the number of stress and health concerns that result from working in a computer environment"
5 0
3 years ago
How does technology improve productivity at
Svetradugi [14.3K]

Answer:

Enables sending documents to multiple

recipients

Provides flexible work schedules and

environments

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • According to the article in WikiAnswers, digital communication systems have more benefits than analog systems. They are faster a
    10·2 answers
  • Which type of JPEG image records the most information in the digital file? Medium Low Fine Expert
    6·2 answers
  • What are the advantages of renting a home over buying a home? What are some disadvantages?
    13·1 answer
  • 4. This is considered to be short term memory because it only holds programs
    14·1 answer
  • A disadvantage of a bus network is that _____. a. failure in one workstation necessarily affects other workstations on the netwo
    7·1 answer
  • What are the similarities and differences between the binary and decimal systems?
    12·1 answer
  • How does technology improve convenience, but impact our privacy?
    8·1 answer
  • A thief has unfortunately captured your atm card number by placing a panel on top of the face of an atm, which was virtually und
    13·1 answer
  • Custom actions help your users by
    6·1 answer
  • Helllp me you will git 16 points
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!