Question

In: Computer Science

write a java code to calculate 1+2-3+4-5 …-99+100

write a java code to calculate

1+2-3+4-5 …-99+100


Solutions

Expert Solution

import java.io.*;
class Main {
   public static void main (String[] args) {
   int num,sum=0;
       for(num=1;num<=100;num++){
       if(num%2==1){
       sum=sum-num;
       }
       else{
       sum=sum+num;   
       }
       }
       System.out.println("sum of series : "+sum);
   }
}


Related Solutions

(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4)...
(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4) Circle 5) TestAllShapes (create 1 object of each type and print the Area for each of them.)
: Please write a MARIE program to calculate 1+2+3+...+100.
: Please write a MARIE program to calculate 1+2+3+...+100.
4. (a) Suppose that τσ=(1 5 2 3)(4) and στ=(1 2 4 5)(3) in S5. If...
4. (a) Suppose that τσ=(1 5 2 3)(4) and στ=(1 2 4 5)(3) in S5. If σ1 = 2, find σ and τ. (b) In Sn, show that σ = τ if and only if σ(τ)^(−1) = ε. ε is the identity permutation. Must be written as a proof. (c) Let σ=(1 2 3) and τ=(1 2) in S3. Show that S3={ε,σ,σ^2,τ,τσ,τ(σ)^2} and that σ^3=ε=τ^2 and στ=τ(σ)^2, then fill out the multiplication table for S3.
coffee tea juice 3 4 5 5 4 3 4 4 4 5 1 2 4...
coffee tea juice 3 4 5 5 4 3 4 4 4 5 1 2 4 2 2 Do a One-way ANOVA by hand (at least once in your life!) …Is there a difference in attention for those who drink coffee, tea, or juice during an 8 a.m. class? Utilize the five steps of hypothesis testing to analyze the following data (p<.01). Attention Ratings (1=no attention- 5=full attention)
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 ....
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 . C) From the point (1,2,3) to the line ?=〈−?,4−?,1+4?〉 .
5 + (3 * 4)^2 - 2 = 147             (5 + 3) * 4^2 -...
5 + (3 * 4)^2 - 2 = 147             (5 + 3) * 4^2 - 2 = 126             (5 + 3 )* (4^2 – 2) = 112             5 + (3 * 4^2) - 2 = 51 Which is the correct answer to using the "order of precedence" and why?
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot the date B: find the line of best fit C: determine ŷ AT x=3 D: Find r and r^2 E: explain r and r^2
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write...
1. Write an algorithm to calculate the Matrix multiplication (or write with pseudo code) 2. Write an algorithm to calculate the recursive Matrix multiplication (or write with pseudo code) 3. Find the time complexity of your pseudo code and analyze the differences
Raysut Cement Company: Strengths: 1- 2- 3- 4- 5- Weaknesses : 1- 2- 3- 4- 5-...
Raysut Cement Company: Strengths: 1- 2- 3- 4- 5- Weaknesses : 1- 2- 3- 4- 5- Opportunities : 1- 2- 3- 4- 5- Threats: 1- 2- 3- 4- 5-
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning...
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning versus Product Process " Please respond to the following: Examine the roles of Enterprise Resource Planning (ERP) and Customer Relationship Management (CRM) in business. Determine how each system can play a critical role in managing value chains. How does LaRosa’s Pizzeria use this technology in order to improve the supply chain and value chain operations? Determine the ways this technology has helped to deliver...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT