Sunday, March 13, 2016

Series Summation In Java

Series Summation In Java - Java programming language tutorial on how to series summation in java.
Series Summation In Java

How to series summation in java

import java.io.*;

class nine{
public static void main(String args[]) throws IOException{
Integer value1,value2,sum,sub,mul,div,temp,loop,series = 0;
String s,s1,s2,s3;

InputStreamReader in = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);

System.out.print("Enter 1st value = ");
s = br.readLine();

System.out.print("Push 2nd value = ");
s2 = br.readLine();

value1 = Integer.valueOf(s);
value2 = Integer.valueOf(s2);
sum = value1+value2;
sub = value1-value2;
mul = value1*value2;
div = value1/value2;

System.out.println("------Output------------------------------------- ");
System.out.println("Addition of two no = "+sum);
System.out.println("Subtraction of two no = "+sub);
System.out.println("Multiplication of two no = "+mul);
System.out.println("Division of two no = "+div);

temp = sum;
sum = div;
div = temp;

temp = sub;
sub = mul;
mul = temp;

System.out.println("-----After Swapping with variable----------------- ");
System.out.println("Addition of two no = "+sum);
System.out.println("Subtraction of two no = "+sub);
System.out.println("Multiplication of two no = "+mul);
System.out.println("Division of two no = "+div);

sum = sum+div;
div = sum-div;
sum = sum-div;

sub = sub+mul;
mul = sub-mul;
sub = sub-mul;

System.out.println("-----After Swapping without variable method 1----- ");
System.out.println("Addition of two no = "+sum);
System.out.println("Subtraction of two no = "+sub);
System.out.println("Multiplication of two no = "+mul);
System.out.println("Division of two no = "+div);

System.out.println("-----Series Summation----------------------------- ");
if(value2 > value1){
for(loop=value1; loop<=value2; loop++){
series = series + loop;
}
System.out.println("Series summation is " + series);
if(series%2==0){
System.out.println("Series summation even number ");
}else{
System.out.println("Series summation odd number ");
}
}else{
System.out.println("Series summation is not possible between "+value1+" & " +value2);
}

}
}


You Like It, Please Share This Article Using...




Don't Forget To Read This Also...




No comments :

Speak Your Mind: