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
The variable points stores data that the user has input. what is the data type of this variable?
kvasek [131]

Answer:

Each variable has a name, a value, and a type. The value might change over time, and that's why its “variable.” Many variables store numbers and strings, like the ones above. Variables can also store other types of data, like lists, dictionaries, and Boolean values

Explanation:

8 0
2 years ago
Explain each kind of pointer and for what it is appropriate
ycow [4]

Answer:

Explanation:

A pointer is nothing but a memory location where data is stored. A pointer is used to access the memory location. There are various types of pointers such as a null pointer, wild pointer, void pointer and other types of pointers. ... When you want to deal different variable data type, you can use a typecast void pointer.

8 0
3 years ago
Read 2 more answers
What is the output? answer = "Hi mom print(answer.lower()) I​
DerKrebs [107]
As you have included a syntax error inside your question, I will make assumptions on the code. I will assume your code is {
answer = “Hi mom”
print(answer.lower())
}

In this case the output would be “hi mom”. Please make sure to double check your questions before posting.
3 0
3 years ago
The five types of personal computers are: desktops, laptops, tablets, smartphones, and
shepuryov [24]

Answer:

microcomputers

Explanation:

8 0
3 years ago
The purpose of a switch______link is to be able to carry the traffic for all local VLANs.
alekssr [168]

Answer:

Inter switch link

Explanation:

It is the inter switch link( ISL) that enables to carry the traffic for all local VLANs. Functions of VLANs are firstly, a VLAN allows us to take one physical switch, and break it up into smaller mini-switches. Secondly, every virtual switch, called VLAN, is simply a number assigned to each switch port.

6 0
3 years ago
Other questions:
  • If you find yourself boxed in by a vehicle on your left or right _____________
    14·2 answers
  • Jackson is teaching the decimal number system. He wants his students to know how to expand numbers by powers of 10. Which is the
    13·2 answers
  • What allows people to create their own radio shows over the internet?
    14·1 answer
  • According to the lecture, when communicating men prefer to concentrate on _____________.
    13·1 answer
  • What is a well-planned strategy that ensures the search and navigation functions are easy to use and user-friendly on a website?
    15·1 answer
  • In your opinion is it more beneficial to have many folders or is it better to nest subfolders
    12·1 answer
  • Celeste is writing a paper. However, two pages in, her computer shuts down unexpectedly. She never saved her paper, and all her
    12·2 answers
  • What layer of the OSI model describes how data between applications is synced and recovered if messages don't arrive intact at t
    12·1 answer
  • If a system contains 1,000 disk drives, each of which has a 750,000- hour MTBF, which of the following best describes how often
    15·1 answer
  • Ninety percent of the fastest-growing jobs require some kind of postsecondary education.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!