0% found this document useful (0 votes)
2 views

Assignment 3

Fhnj

Uploaded by

aditparashar26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 3

Fhnj

Uploaded by

aditparashar26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Main.

java
java - cp /tmp/TwMdxXUCDh Sum_Odd Even
1 import java.util.Scanner;
Enter the number of elements in array:6
2 public class Sum_Odd_Even Enter the elements of the array:1
3- {
2
4 public static void main(Stringt] args) 3
5
4
6 int n, sum_ E =0, sum_0 = 0;
5
7 Scanner s =new Scanner (System. in) ;
6
8 System.out-print("Enter the number of elements in array:");
Sum of Even Numbers:12
n = s.nextInt 0;
Sum of Odd Numbers:9
10 int[] a = new int [n];
11 System.out-println("Enter the elements of the array: ");
12 for(int i =0; i < n; i )
13
14 a[i] = s.nextInt();
15
16 for(int i =0; i< n; i+)
17
18 if(a[i] %2 == 0)
19
20 Sum E = Sum E a[i];
21
22 else
23 {
24 Sum 0 = Sum 0 a[í]; I
25
26
27 System.out-println("Sum of Even Numbers:"-sum_E);
28 System.out-println(" Sum of Odd Numbers:"+sum_0);
29
30 }

o Type here to search


programiz.com/java progiaming/onihe om

rogramiz Online Java Compiler

Main.java Run Output


1- import java.util.Scanner; java -cp /tmp/Yj3MGk1m0Z PowerOfNumber
2class PowerOfNumber { Enter the base number :7
3 public static void main(String args ]){ Enter the exponent nuber 222
4
Scanner sc = new Scanner (System. in); Result of 7 power 2 fS 49
5 System.Out.println(" Enter the base number :: "):
6 int basse = sc. nextInt ():
7 int temp = base;
System.out.print("Enter the exponent number :: ");
9 int exp sc.nextInt() :
10
11 for (int i=1; i<exp; i ) {
12 temp = temp*temp:
13
14 System.out - princin("Result of " base power GXp is
temp):
15
16
Malnjava Run Output
1 //Java Program to find sum of series Java cp /tmp/SHx9bdfSER SumotSer.
2- Amport java ut1l,*! Enter the number:
10
4 elass SumOfSeries ( Sum 1s 2.92896
Scanner se neW Scanner(System. n)
Ant n SEnextBnt()
Statie double sum(int n)

double 1, & 0.0:


10

return S

14
publie static veid main(String argst)
16
17 Scanner sE new Scanner tSysten,in) :
18 Syste,out.printint"Enter the number: "):
t9 int n e st.nextlntt):
20 Systemout-printft"Sum is $", suntn):
21
22

You might also like