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

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.
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
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...
[ 1 -1 3 -3 5 2 ] A=[ 1 -1 4 -1 9 -4 ]...
[ 1 -1 3 -3 5 2 ] A=[ 1 -1 4 -1 9 -4 ] [ -1 1 -3 3 -4 8  ] [7] b=[5] [4] use the row reduction algorithm to solve the following Describe the solution set of Ax=b in parametric vector form describe the solution set of Ax=0 as Span[ V1,V2,....,Vp]
Write a java code that: 1) Takes as an argument an integer number, say N 2)...
Write a java code that: 1) Takes as an argument an integer number, say N 2) Creates an array of size N 3) Populates the array with random numbers between 0 and 10 * N. This is, the values of the elements of the array should be random numbers between 0 and 10 * N. 4) Finally, the code outputs the index of the smallest element and the index of the largest element in the array
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
please write the java code so it can run on jGRASP Thanks! 1 /** 2 *...
please write the java code so it can run on jGRASP Thanks! 1 /** 2 * PassArray 3 * @Sherri Vaseashta 4 * @Version 1 5 * @see 6 */ 7 import java.util.Scanner; 8 9 /** 10 This program demonstrates passing an array 11 as an argument to a method 12 */13 14 public class PassArray 15 { 16 public static void main(String[] args) 17 { 18 19 final int ARRAY_SIZE = 4; //Size of the array 20 // Create...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT