0% found this document useful (0 votes)
8 views1 page

Java Program for Positive Integer Sum

Uploaded by

madipeddi0
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)
8 views1 page

Java Program for Positive Integer Sum

Uploaded by

madipeddi0
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

package DSA.

Assigment1;

import [Link].*;
import [Link];

public class Main {


public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter the value of k: ");
int k = [Link]();
[Link]("Enter the number of elements you want to enter: ");
int n = [Link]();
int[] arr = new int[n];
[Link]("Enter the elements inside the array: \n");
for(int i=0; i<n; i++){
arr[i] = [Link]();
}

[Link]("Elements inside the array are: ");


for(int i : arr){
[Link](i + " ");
}

List<Integer> posArr = [Link](arr)


.boxed()
.filter(num -> num > 0)
.sorted()
.collect([Link]());

[Link]("\nFiltered array: ");


for(int i : posArr){
[Link](i + " ");
}

int sum = 0;
for(int i = k; i < [Link](); i++){
sum += [Link](i);
}

[Link]("\nSum: " + sum);


}
}

You might also like