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
Svetlanka [38]
2 years ago
8

Write a public static method named evens that takes in 1 argument int a, and returns a String containing all positive even numbe

rs with each separated by a comma from O up to that number inclusive if it is also even
Remember if the argument is odd not to include it in the output
Remember there should be no trailing comma after the values
If the argument a is negative return a String that says "NONE!
(Do not print the String)
Example evens(5) String returned by method. 0.2.4
Example evens(8) String returned by method. 0.2.4,6,8
Example evens (9) String returned by method 0.246,8
Example evens(-5), String returned by method: NONE
Example evens(O) String retumed by method 0
Example evens(1) String returned by method 0
Computers and Technology
1 answer:
topjm [15]2 years ago
4 0

public class JavaApplication48 {

   public static String evens(int a){

       String txt = "";

       if (a < 0){

           return "NONE!";

       }

       else if(a%2 == 1){

           a -= 1;

       }

       for (int i = 0; i <= a; i+=2){

           if (i < a){

               txt += i+",";

                       }

           else{

               txt += i;

           }

       }

       return txt;

   }

   public static void main(String[] args) {

       System.out.println(evens(1));

   }

   

}

I hope this helps!

You might be interested in
Consider a multidimensional array A stored in row-major order with 22 rows and 6 columns whose subscripts start at 0. If each el
siniylev [52]

Answer:

Option c is the correct answer for the above question.

Explanation:

  • If the array will store in row-major order, then it will be a store like the first row, then second row and then third row.
  • If the user wants to conclude the address of the A[3,5], then the address of the A[3,5] will be 184.
  • It is because the 3 states the row number and the 5 states the column number.
  • The above question states that every value take 8 bit. and there are 4 rows from 0 to 3 and 6 column (0 to 5) for every row (except the fourth rows because it takes 5 columns from 0 to 4) before the A[3,5].
  • So there are 23 value before A[3,5] which are as-- [00,01,02,03,04,05][10,11,12,13,14,15][20,21,22,23,24,25][30,31,32,33,34].
  • So when every value takes 8 bit then 23 value takes 184 bits(23*8).
  • So the address of A[3,4] is 184.
  • Hence option c is the correct and the other is not because of 184 stated from the c option only.
4 0
3 years ago
Which type(s) of license(s) allow the underlying software code to be viewed?
morpeh [17]

Answer:

The correct answer is B. Free software.

Explanation:

Free software is a term used for software that the holder can use, copy, read, modify and distribute with or without modification at will. Software that falls under this category includes software that is not protected by copyright laws or software that is licensed to be used in this way.

Motives for developing free software can be technical, economic or social. What is significant for developers is the desire to develop as producers of programs by learning from other producers. The desire to help others is also a major motive.

8 0
2 years ago
If an occupation is projected to decline by 7% over the next 10 years, how would you rate the job outlook?
Helen [10]
Steady sounds like the best answer but that’s tough
5 0
3 years ago
What does this sign mean?
yKpoI14uk [10]
A. yield to the car on your right
8 0
3 years ago
Read 2 more answers
Please help me on this coding problem :)
Vesnalui [34]

Answer:

a=4 , b=1

Explanation:

I'm not a computer science major at all but I think I can help you with this code.

Our program wants us to add 2 to a get new a value while also subtracting 1 from b value to obtain new b value. We we want to for for as long b is not 0 and a/b is nonnegative.

One round we get:

New a=0+2=2

New b=3-1=2

Let's see if we can go another round:

New a=2+2=4

New b=2-1=1

We can't go another round because b would be negative while a is positive which would make a/b negative. So our loop stops at this 2nd round.

a=4 , b=1

Other notes:

2nd choice makes no sense because a is always going to increase because of the addition on a and b was going to decrease because of the subtraction on it.

Third choice makes no sense because a/b doesn't even exist.

Fourth choice a/b is negative not nonnegative.

4 0
3 years ago
Other questions:
  • ll of the following are extra precautions you can take to secure a wireless network EXCEPT ________. Select one: A. turn on secu
    9·1 answer
  • HURRY
    5·1 answer
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    9·1 answer
  • The date June 10, 1960, is special because when it is written in the following format, the month times the day equals the year:
    5·1 answer
  • How is kerning used in Word?
    7·2 answers
  • How many of the colonists of Jamestown died before they made it to shore, due to the difficult voyage?
    15·1 answer
  • ساعدوني على الإجابة على هذه الأسئلة
    11·1 answer
  • Sharon must give an informative presentation to a group of teenagers about cultivating earthworms for use in home gardening. Whi
    11·2 answers
  • Consider the following code segment
    15·1 answer
  • Why does my roku tv keep disconnecting from the internet.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!