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
What's the risk or effect of software piracy?
slamgirl [31]
You can go to jail get in alot of trouble plus you always have a chance of letting a virus into yoru computer
7 0
3 years ago
Read 2 more answers
In 1971, Intel created and marketed the first microprocessor chip, called the Intel 4004. What was significant about this invent
PilotLPTM [1.2K]
The answer is D

<span>D) It allowed computers to be smaller because the chip allowed for the creation of computer components with varying capabilities.</span>
7 0
3 years ago
What are basic difference between variable and data type in the c? ​
OLga [1]

Answer:

there is lot of difference

7 0
2 years ago
The science of networking is attributed to which government's involvement?
worty [1.4K]

Answer:

The United States

if I am not mistaken

6 0
2 years ago
Write a Java program that can calculate and print out the area of a circle. The user enters data of the radius and its measureme
mezya [45]

Answer:

// program in java.

// package

import java.util.*;

// class definition

class Main

{

   // main method of the class

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

{

   try{

  // Scanner object to read input

Scanner scr=new Scanner(System.in);

 // variables

double rad;

String unit1="in";

String unit2="ft";

String unit3="cm";

String unit4="m";

// ask user to enter radius

System.out.print("Enter the radius: ");

 // read radius

rad=scr.nextDouble();

 // check radius is negative or not

while(rad<0)

{

    System.out.println("Radius can't be negative:");

     // ask again to enter radius

    System.out.print("Enter the Radius again:");

     // read radius again

    rad=scr.nextInt();

}

// ask user to enter the unit of measurement

System.out.print("Enter the unit (\"in\" for inch, \"ft\" for feet, \"cm\" for centimeter, and \"m\" for meter):");

 // read unit

 String unt=scr.next();

 // calculate area

double area=3.14*rad*rad;

 // print area and unit

if(unt.equals(unit1))

    System.out.println(area+" inch.");

else if(unt.equals(unit2))

    System.out.println(area+" feet.");

else if(unt.equals(unit3))

    System.out.println(area+" centimeter.");

else if(unt.equals(unit4))

    System.out.println(area+" meter.");

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read radius of circle from user with Scanner object and assign it to variable "rad".Check the radius is negative or not.If the radius is negative ask user to enter radius again until user enters a positive radius.Then read the unit of measurement.calculate the area of circle and print area with unit.

Output:

Enter the radius: -4

Radius can't be negative:

Enter the Radius again:6

Enter the unit ("in" for inch, "ft" for feet, "cm" for centimeter, and "m" for meter):cm

Area of circle is 113.03999999999999 centimeter.

5 0
3 years ago
Other questions:
  • Jason works as an accountant in a department store. He needs to keep a daily record of all the invoices issued by the store. Whi
    13·2 answers
  • An iframe is an inline table for a website. True False i need an answer fast
    15·1 answer
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • . Which of the following is NOT an option for increasinghard drive storage space?
    6·1 answer
  • All of the following are reserved keywords in C++ EXCEPT
    5·1 answer
  • Create a program that asks the user to enter grade scores. Use a loop to request each score and add it to a total. Continue acce
    9·1 answer
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • Use the Law of Sines to solve the triangle. Round your answers to two decimal places.
    6·1 answer
  • The cat store needs your help! The base class Animal has private fields animalName, and animalAge. The derived class Cat extends
    9·1 answer
  • the front desk of the Nocete's Hotel will comlute the total room sales (TRS) of Room 101.The room was occupied three times and t
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!