Write a java program that finds the sum of all even numbers between 1 and 55.

Also what modification would you do to the program if you wanted the sum of all odd numbers between 1 and 55

Answers

Answer 1

Answer:

For sum of  even Number :

public class even{

    public static void main(String []args){

       int sum = 0;

       for(int i=1;i<=55;i++){

           if(i%2==0){

               sum = sum + i;

           }

       }

       System.out.println(sum);

    }

}

Modification for sum of odd:

change the condition of if statement:

i%2==1 instead of i%2==0

Explanation:

create the main function and declare the variable with zero.

Then, take a for loop for traversing the number from 1 from 55.

Inside the for loop, if statement check the condition for even number

A number is even if number divide by 2 and give zero reminder.

so, number%2==0  it is the condition for even number.

then add the even number until condition TRUE.

and finally print the result.

Modification for sum of odd number:

A number is odd, if number divide by 2 and give one reminder.

it means, number%2==1  it is the condition for odd number.

just change the if condition with above.


Related Questions

FS and GS are two___________________ in protected mode.
? segment registers
? segment selectors
? stack pointers
? register pointers

Answers

Answer:

Segment registers

Explanation:

The initial purpose behind the segment registers was to enable a program to access many distinct (big) memory sections designed to be autonomous and part of a constant virtual store.

They don't have a processor-defined objective, but instead Operating system runs them for purpose. The GS register is used in Windows 64-bit to point to constructions defined by the operating scheme.   Operating system kernels usually use FS and GS to access thread-specific memory. In windows, thread-specific memory is managed using the GS register. To access cpu-specific memory, the linux kernel utilizes GS.

Decision trees are best suitedfor:
one decision inone period.
one decision overseveral periods.
several decisionsover one period.
several decisionsover several periods.
None ofthese.

Answers

Answer: Decision Trees are best suited for several decisions over one period.

Explanation:

Decision tree gives an effective method for making decisions. It is a tree-like model used for decisions and analyses consequences, including resources cost, outcome and utility. It also helps us to make best and good quality decisions on the basis of given information. It is also widely used in machine learning and commonly used  in data mining as a tool.

In a ____ queue, customers or jobs with higher priorities are pushed to the front of the queue.

A.
structured

B.
divided

C.
priority

Answers

Answer: In a priority queue, customers or jobs with higher priorities are pushed to the front of the queue.

Explanation:

A queue is an abstract data type which is an ordered set of elements. The elements are served in the order in which they join the queue. The first element which was put in the queue is processed first.  

The operations performed on queue data type are dequeue and enqueue.

Dequeue refers to removal of the first element from the queue after it has been serviced.

Enqueue refers to the arrival of new element when the element is added at the end of the queue.

A priority queue is another implementation of a queue. All the elements in a priority queue are assigned a priority. The element with the higher priority is served before the element with a lower priority. In situations of elements having same priority, the element is served based on the order in which the element joined the queue.

In programming, a priority queue can be implemented using heaps or an unordered array. Unordered array is used based on the mandatory operations which are performed on the priority queue.

The mandatory operations supported by a priority queue are is_empty, insert_with_priority and pull_highest_priority_element. These operations are implemented as functions in programming.

The is_empty confirms if the queue is empty and has no elements.

The insert_with_priority puts the new element at the appropriate position in the queue based on its priority. If the priority of the element is similar to the priority of other element, the position of the new element is decided based on the order of joining the queue.

The pull_highest_priority_element pulls the element having the highest priority so that it can be served before other elements. The element having the highest priority is typically the first element in the priority queue.

In operating system, priority queue is implemented to carry out the jobs and/or tasks based on their priority.

Class objects cannot be passed as parameters to functions or returned as function values.

True

False

Answers

I think true but I am not sure

Final answer:

The statement is false; class objects can indeed be passed as parameters to functions and returned as function values in many object-oriented programming languages.

Explanation:

The statement that class objects cannot be passed as parameters to functions or returned as function values is false. In many programming languages, especially those that support Object-Oriented Programming (OOP), it is common to pass objects as arguments to functions or methods, and also to return them as function values. This is part of the encapsulation feature in OOP, where an object bundles data and methods that operate on that data, allowing the methods direct access to the object's data without necessarily passing them as individual parameters.

For example, consider a Python class named Book. You can create an instance of this class and pass it to a function:

def display_book_info(book):
   print(book.title)
   print(book.author)

my_book = Book("Pride and Prejudice", "Jane Austen")
display_book_info(my_book)

In this case, my_book, which is an object of the class Book, is being passed as a parameter to the function display_book_info.

Which of the following electronic payments is ideal for micropayments?

A. purchasing cards

B. smart cards

C. none of the methods listed

D. electronic checks

Answers

Smart cards are ideal for micropayments.

What is the output after the following code executes?

int x=10; if ( ++x > 10 ) {

x = 13;

}

cout << x;

Answers

Answer:

13

Explanation:

First understand the meaning of ++x, it is a pre-increment operator.

it means, it increase the value first than assign to the variable.

For example:

x=10

then after executing  ++x, the value of x is 11.

it increase the value and assign to x.

In the question:

The value of x is 10. After that, program moves to the if condition and check for condition (++x > 10) means (11 > 10) condition true.

then, 13 assign to x.

After that value of x is printed as 13.

Final answer:

The C++ code increments the variable x to 11 due to the pre-increment in the if statement, then changes x to 13 within the if block. Thus, the output of the code, when executed, is 13.

Explanation:

When the C++ code provided is executed, the statement int x=10; initializes the variable x with the value 10. The subsequent if statement checks if ++x > 10, where ++x is a pre-increment operation that increases x by 1 before the comparison. Since x is incremented to 11 before the comparison, the if block is executed, setting x to 13. The cout << x; statement then outputs the value of x, which at this point will be 13.

The characters << indicate that the value to the right is to be sent to the cout, which identifies the standard output stream. For cout to work, we need the inclusion of the iostream header file and the usage of the using namespace std; directive.

Write each of the following decimal values in binary. (Can please show me how you did arithmetic you to perform the conversion.)
47
14
81
102
241

Answers

Answer:

47 → 101111

14 → 1110

81 → 1010001

102 → 1100110

241 → 11110001

Explanation:

There are two ways to calculate binary equivalent of decimal values:

Divide the number by 2 as in the image, keep the reminder to right. then divide the divisor by 2 and keep the reminder to right and so on. Then read the reminders from top to bottom.Or you can start putting 1 at the nearest power of 2 that is smaller than decimal integer, then subtract that value from the decimal integer. Again put 1 at nearest power of 2 and so on.

       e.g.

       For 102, we put 1 at 64. than 102[tex]-[/tex]64 = 38

                      then put 1 at 32, now 38 [tex]-[/tex] 32 = 6.

                      then put 1 at 4, now 6 [tex]-[/tex] 4 = 2.

                      then put 1 at 2, now 2[tex]-[/tex]2 = 0.

                      so put 0 at 1 and all other places except those where we put 1.

Which keyboard shortcut is typically used to move to the previous entry box?

A. Ctrl+Enter
B. Tab
C. Enter
D. Ctrl+Tab

Answers

Answer:

D. Ctrl+Tab

Explanation:

The Ctrl+Tab shortcut is typically used to move to the previous entry box.

Write a C++ program that determines if a given string is a palindrome. A palindrome is a word or phrase that reads the same backward as forward. Blank, punctuation marks and capitalization do not count in determining palindromes. Here is some examples of palindromes:

Radar
Too hot to hoot
Madam!I'm adam

Answers

A C++ program to determine if a given string is a palindrome involves converting the string to the same case, removing non-alphanumeric characters, and then checking if the string is equal to its reverse. Below is a sample code that performs these steps:

#include

#include

#include

#include

bool isPalindrome(const std::string& str) {

   std::string sanitized;

   for (char ch : str) {

       if (std::isalnum(ch))

           sanitized += std::tolower(ch);

   }

   std::string reversed = sanitized;

   std::reverse(reversed.begin(), reversed.end());

   return sanitized == reversed;

}

int main() {

   std::string input;

   std::cout << "Enter a string to check if it is a palindrome: ";

   std::getline(std::cin, input);

   bool result = isPalindrome(input);

   if(result) {

       std::cout << "The string is a palindrome." << std::endl;

   } else {

       std::cout << "The string is not a palindrome." << std::endl;

   }

   return 0;

}

In the above program, the function isPalindrome takes a string and creates a sanitized copy by iterating over each character, checking if it is alphanumeric (ignoring spaces and punctuation), and converting it to lowercase. After constructing the sanitized string, it creates a reversed version and compares the two. The main function reads a string from the user, calls the isPalindrome function, and outputs the result.

. If you executean infinite recursive function on a computer it will executeforever.
a. True
b.False

Answers

Answer:

b. False

Explanation:

If you execute an infinite recursive function on a computer it will NOT execute forever.

What is the advantages and disadvantagesof International Standards for NetworkProtocols.

Answers

Answer:

Advantages and disadvantages of international standards for network protocols are:

Advantages -

Due to common underlying standard maintenance and installation become easy. Many computers can connect together from all the worldwide, as they are using the international standard for network protocol. One of the main advantage using international standard as it boost up growth and economy.

Disadvantages -

Every network standard has its own limitations in a particular domain. Once it is spread worldwide then it is difficult to resolve network issues.

Write a program which prompts user to enter a character, if the user presses „Z‟, the program asks user to enter a number. In this case the program implements 5-input majority voting logic which is explained as follows.The value of the number represented by the five leftmost bits of Register-B is tested. If the number of logic '1' bits (in the 5 leftmost bits) is greater than the number of logic '0' bits, the program should output: "The number of 1’s in the 5 left most bits is greater than the number of 0’s". If the number of logic '0' bits (in the 5 leftmost bits) is greater than the number of logic '1' bits, the program should output: "The number of 0’s in the 5 left most bits is greater than the number of 1’s"

Answers

I’m pretty sure the answer is A

One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input, and outputs the number of laps. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue); Ex: If the input is:

Answers

Answer:

import java.util.Scanner;

public class Miles {

public static void main(String[] args) {

   //initialization

       double Number_Miles;

       //print the message

       System.out.print("Enter the number of miles: ");

       Scanner scn1 = new Scanner(System.in);

       

       Number_Miles = scn1.nextDouble();  //read the input from user

       //calculate the laps

       double yourValue = Number_Miles/0.25;

       //display the output on the screen

       System.out.printf("%.2f", yourValue);

     

}

}  

Explanation:

First import the library Scanner than create the class and define the main function. In the main function, declare the variables.

print the message on the screen and then store the value enter by the user into the variable.

Scanner is a class that is used for reading the output. So, we make the object of the class Scanner and then object call the function nextDouble() which reads the input and store in the variable.

After that, calculate the number of laps by dividing the number of miles with the given one lap running track value (0.25 miles).

[tex]Number\,of\,laps = \frac{Number\,of\,miles}{0.25}[/tex]

the output is stored in the variable.

After that, print the value on the screen with 2 digits after the decimal point.

we can use "%.2f" in the printing function in java.

like System.out.printf("%.2f", output);

Answer:

def miles_to_laps(miles):

  return miles / 0.25

miles = 5.2

num_of_lap = miles_to_laps(miles)

print("Number of laps for %0.2f miles is %0.2f lap(s)" % (miles, num_of_lap))

Explanation:

A ____________________ can be used to hierarchically represent a classification for a given set of objects or documents. A. taxonomy B. framework C. scheme D. standard

Answers

Answer:

A. taxonomy

Explanation:

A taxonomy can be used to hierarchically represent a classification for a given set of objects or documents.

What is the height of the tallest possible red-black tree containing 31 values?

Answers

Answer:

The height of tallest possible red-black tree having 31 values is 10.

Explanation:

The height of tallest possible red-black tree = 2㏒₂(n+1)

here we have n=31 So substituting the value of n in the equation.

=2㏒₂(31+1)

=2㏒₂(32)

=2㏒₂(2⁵)                   since ㏒(aⁿ)=n㏒(a)  

=2x5㏒₂(2)

=10㏒₂(2)                   since ㏒ₙ(n)=1.

=10.

.The operation signature has all the following except:
A.name of the operation B.object accepts C.algorithm ituses D.value returned by the operation

Answers

Answer: C) algorithm it uses

Explanation: The operation signature has the name of operation ,objects that it accepts and the value returned by the operation but it does not have algorithm that it uses.As algorithm defines all the steps that are to be used to find the result so signature operation does not include the whole algorithm that is to be used. The signature operation verifies the steps of the algorithm in way.

What applications work best with multiplexing?Why?

Answers

Answer:

Multiplexing is the process of combining multiple analog and digital signal into one signal over a shared medium and it is most efficient service, which is provided by the transport layer protocol. The main purpose of multiplexing is that signal are transmitted efficiently.

It contains applications as:

Client-server Application

Many to single client-server application

Many to many client-server application

Many client to many server application is the best because it is improving server application and processing a client request within a group on any server.

ETL stands for ---------------o Extract, transform and loado Extended transformation loadingo Enhanced logical transformation

Answers

Answer:

Extract, transform, and load

Explanation:

ETL stands for extract, transform, and load.

In Online Data Extraction data is extracteddirectly from the ------ system itself.o Hosto Destinationo Sourceo Terminal

Answers

Answer:

system itself.

Explanation:

In Online Data Extraction data is extracted directly from the system itself.

What is the difference between an argument and a parameter variable?

Answers

Answer:

The value enter in the function calling is called argument. Argument passed to function.

The variable declare in the function to capture the pass value from the calling function is called parameters.  

Explanation:

Argument is used in the calling function and parameter is used in the defining the function.

for example:

//create the function

int count(parameter_1, parameter_2,.....)

{

  statement;

}

count(argument_1. argument_1,.....);   //call the function

What are the attributes of agood Software Test?

Answers

Answer:

The features of a software test to be efficient are basically used to measure the quality control so that prevention can be provided from the errors or sort of defects. These characterstics are used for quality assurance and focuses on detecting the efficiency of the products and  its services.  

The some characteristics of a good software test are as follows:

Testing-ability - System should reliable on detection of any failure or error.

Efficiency -should be reliable enough to carry out tasks .

Reusability - Should be useful for several purpose at different times.

Maintainability - maintenance should be easy and efficient.

How do you return a value from a function?

Answers

Answer:

return instruction used to return a value from a function.

Explanation:

Function is a block of statement which perform the special task.

Syntax for define a function:

type name(parameter_1, parameter_2,...)

{

  statement;

return variable;

}

In the syntax, type define the return type of the function. It can be int, float, double and also array as well. Function can return the array as well.

return is the instruction which is used to return the value or can use as a termination of function.

For return the value, we can use variable name which store the value or use direct value.

Data mining must usestatistics to analyze data.
True
False

Answers

Answer: True

Explanation: In data mining, they use statistics component for the analyzing of the large amount of data and helps to deal with it. Statistics provide the techniques for the analyzing, evaluating and dealing with the data that is known as data mining.Data statistics provide the help to organize large data in a proper form and then analyze it. Thus, the statement given is true that data mining must use statistics to analyse data.

In ________ for final fields and methods the value is assignedlater but in ______ you assign the value during declaration.
Java , C++
C++ , C#
Java , C#
C++ ,Java

Answers

Answer:

The answer to this question is Java,C++.

Explanation:

We can assign non static final variables a value with the declaration or in the constructor but this is not the case with c++ because we have to assign value during declaration and c++ equivalent of final is const keyword and there is sealed or readonly keywords in c# not final.If we do not assign value at the time of declaration the const variable will contain garbage value which cannot be changed afterwards.

Answer:

The answer to this question is Java,C++.

Explanation:

We can assign non static final variables a value with the declaration or in the constructor but this is not the case with c++ because we have to assign value during declaration and c++ equivalent of final is const keyword and there is sealed or readonly keywords in c# not final.If we do not assign value at the time of declaration the const variable will contain garbage value which cannot be changed afterwards.

What is transaction? Differentiate between pre-emptiveand non pre-emptive transactions

Answers

Answer: Transaction is the process of processing information in a standalone system or distributed system. There are two basic types of systems which are preemptive and non preemptive transactions.

Explanation:

Transaction can be complete successfully or it can fail but it can never be partially completed. Computer processes which completes in its entirety or  does not complete at all are termed as processes.

Preemptive processes are those where the cpu is allotted to a process for a definite time . The cpu can be given to another process if it has higher priority.

Whereas in non preemptive processes the cpu once allotted to a process cannot be assigned to another process until job is finished for the first process.

The purpose of a database is to help people stop using spreadsheets.

Answers

Answer:

Yes, the purpose of a database in a way is to stop people from using spreadsheets but, it is also so much more.

Explanation:

Databases are a vastly improved form of a spreadsheet. They allow Computer Scientists to automatize a company's information. Giving them the ability to instantly add, retrieve, and modify specific information within a database of hundreds or even thousands of entries. All this with little or no human input. Thus saving a company time and money as opposed to using a regular spreadsheet which requires manual input from an employee.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

What is stand-alone LDAP server?

Answers

Answer:

A stand-alone LDAP server is defined as to remove the load from a server that does multi function tasks. It is more efficient when we use one or more LDAP configurations .

Light weight Directory Access Protocol (LDAP) is a client and server protocol used for accessing directory data. It  helps in reading and editing the directories over IP networks and runs directly over Transmission control protocol and internet protocol used simple string format for transferring of data.

for a small to medium enterprise , the benefits of setting up an e-commerce store front include ( choose all that apply)

A. The ability to offer a larger selection of products

B. the ability to reach a wider customer base

C. the ability to eliminate advertising

D. the ability to offer lower prices to customers

Answers

Answer:

All of the above

Explanation:

The ability to reach a wider customer base, the ability to offer lower prices to customers, the ability to offer a larger selection of products and the ability to eliminate advertising. The correct options are A, B, C and D.

What is e-commerce store front?

An electric storefront is a web-based solution that allows business owners to advertise and sell goods and services over the internet.

This is a fundamental form of e-commerce in which the buyer and seller interact directly.

To enable merchants to sell their products online, it combines transaction processing, security, online payment, and information storage.

A storefront, also known as a shopfront, is the facade or entryway of a retail store on the ground floor or street level of a commercial building, typically with one or more display windows.

A storefront's purpose is to draw attention to a company and its products.

The makes it possible to reach a larger customer base, to offer lower prices to customers, to offer a larger selection of products, and to eliminate advertising.

Thus, all options are correct.

For more details regarding storefront, visit:

https://brainly.com/question/971394

#SPJ2

If a CPU receives theinstruction to multiply the byte-sized values $12 and $3E, thisaction will take place in the ______________ (part of internal CPUhardware) section of the CPU.

Answers

Answer: Arithmetic and logic unit(ALU)

Explanation:  In central processing unit (CPU) , there are two main units CU(control unit) and ALU (arithmetic and logic unit) . ALU is responsible for any sort arithmetic and logical operation in the processor.This unit can perform mathematical operation like addition , multiplication divide , logical and many more. So the given operation of multiplication in the question will be done bu ALU of the CPU.

Discuss briefly general-purpose graphicsprimitives that contain 2D graphics library.

Answers

Answer:

  General purpose graphics primitives that contain 2D graphic library as, it is used in graphics processing unit which typically manage computation for computer graphics. Graphic primitives contain basic element such as lines and curves. Modern 2D computer graphic system that operate with primitives which has lines and shapes. All the elements of graphic are formed from primitives.

Other Questions
ASAP!!PLSBoth the Stamp Act and the Townshend Acts resulted in:A. British changes to the Quartering Act.B. colonial boycotts of British goods.C. British alliances with Native Americans.D. colonial shortages of paper goods. What is the solution to the system of equations below when graphed?y=3x+1y=4x-1 A. (3,4) B. (1,-1)C. (6,8)D. (2,7) Help on 10 and 11 and give me the answers for the blank ones Continental shields are ____.coastal mountain rangeslarge, inland basinslines of volcanic islands that parallel a continents coastareas of crust added to a continent by accretionareas of exposed, ancient crystalline rocks At time t0 = 0 the mass happens to be at y0 = 4.05 cm and moving upward at velocity v0 = +4.12 m/s. (Mind the units!) Calculate the amplitude A of the oscillating mass. Answer in units of cm. A sample of N2 gas occupying 800.0 mL at 20.0C is chilled on ice to 0.00C. If the pressure also drops from 1.50 atm to 1.20 atm, what is the final volume of the gas? Which equation should you use What is the area of a rectangle with a length of 27 and a height of 56? No quera dejar mi coche en el aeropuerto toda la semana, llam un taxi. Question 2 with 1 blank Me encontr con un amigo y l viajaba en el mismo vuelo que yo. Question 3 with 1 blank Hubo una demora en la salida del vuelo: , el piloto no lleg a tiempo. Question 4 with 1 blank Mi amigo estaba nervioso y me dijo: " , tengo miedo de viajar en avin". Question 5 with 1 blank Me cambi de asiento y me sent al lado de mi amigo, me necesitaba. Question 6 with 1 blank El vuelo lleg tarde, el servicio fue malo, la comida estaba fra y la lnea area perdi mis maletas. perform the indicated operation 1 1/3 3 3/4 Use the figure to decide the type of angle pair that describes Why was a second control group was included in this experiment A person's website specializes in the sale of rare or unusual vegetable seeds. He sells packets of sweet-pepper seeds for $2.32 each and packets of hot-pepper seeds for $4.56 each. He also offers a 16-packet mixed pepper assortment combining packets of both types of seeds at $3.16 per packet. How many packets of each type of seed are in the assortment?There are _____packets of sweet-pepper seeds and _____- packets of hot-pepper seeds. The earth art of christo and jean-claude did not alter the land, but rather ___. What is the product?(4y - 3)(2y2 + 3y 5)8y3 + 3y + 158y3 23y + 158y3 - 6y2 - 17y + 15O 8y2 + 6y2 - 29y + 15 How many millimeters are in 8 meters? A 6 kg penguin gets onto a Ferris Wheel, with a radius of 5m, and stands on a bathroom scale. The wheel starts rotating with a constant acceleration of .001 rad/s2 for two minutes and then runs at a constant angular velocity. After the wheel is rotating at a constant rate, what is the penguins a) angular momentum about the center of the Ferris Wheel, b) tangential velocity c) maximum & minimum readings on the bathroom scale (and where do they occur?) WHEN gEORGE AND aNTHEA WERE MARRIED 120 OF THE GUEST aNTHEA'S FAMILY OR FRIENDS. THIS WAS 60 PERCENT OF THE TOTAL number of guest. How many guest were altogether ? what is the answer for 2a x -a? place parenthesis in the expression below to make it a true statement.5+55X5=0 The Internet began when the U.S. Department of Defense was looking for a computer network that would continue to function in the event of a disaster. TrueFalse