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
If you enter a command and want to terminate its execution before it is finished, you can press ____ to do so.
sertanlavr [38]
If you mean on the phone you can press the home button. if you mean on the computer you could press esc
5 0
2 years ago
Read 2 more answers
Computer programs can be opened from _____.
gladu [14]
Computer programs can be opened from _____.

all of the above
3 0
3 years ago
Read 2 more answers
A company that connects through your communications line to its server, which connects you to the Internet, is a(n)
hammer [34]
Internet server provider
4 0
3 years ago
What was one complication caused by the tsunami that struck japan in 2011?
Gekata [30.6K]

Answer:a

Explanation:

6 0
2 years ago
Which is the latest ICT policy?​
galina1969 [7]

Answer:

There is no updated policy

Explanation:

If you like my answer than please mark me brainliest thanks

7 0
3 years ago
Read 2 more answers
Other questions:
  • You need to fax a portion of a map from a large hard-cover atlas to a client from an internal fax-modem. To fax the map, the bes
    14·1 answer
  • A(n) ____ algorithm is a set of specific, sequential steps that describe in natural language exactly what a computer program mus
    5·1 answer
  • Select the answer that best describes what an opportunity cost is?
    8·2 answers
  • Is your florida learners license number the same as the actual license number?
    14·2 answers
  • Green computing involves reducing electricity consumed and environmental waste generated when using a computer. which of the fol
    5·1 answer
  • SOLVE IN C:
    10·1 answer
  • When calling a function with arguments that should be modified, the __________ of those arguments are passed.
    5·1 answer
  • Mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
    9·2 answers
  • Does technology need to be kept alive?
    5·2 answers
  • There is overlap in the subjects of study in the different information technology disciplines.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!