Question: ex 1 . Input: 1 0 2 5 8 1 0 2 2 2 3 3 4 5 1 0 Output : 7 ex 2

ex1. Input:
1025
810222334510
Output : 7
ex2 input
1357
241211917565121377
Output : 30
ex3 input
1026
810222334510
Output : 5
Complete the code using Java language.
10 is the total member size
2 is the initial member, 5 is the final member.
num[i] is an array to store members.
1. I want to store members into a new array, such as
I want to store 2 to 5 with members being
810222334510
which wants to collect 2 to 5, namely 2223345
2. Then remove the numbers from least to greatest in the array, which is 2345, so there will be 223.
3. Add the remaining numbers together 2+2+3=7
4. If in the member num[i] is not equal to end, display the answer end-1 at all.
Completely edit my code.
"
import java.util.ArrayList;
import java.util.Scanner;
public class test {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
ArrayList list = new ArrayList<>();
int size = input.nextInt();
int start = input.nextInt();
int end = input.nextInt();
int num[]= new int[size];
for(int i =0; i < size; i++){
num[i]= input.nextInt();
}
int newNum[]= new int[size];
for(int i =0; i < size; i++){
if(num[i]>= start && num[i]<= end){
newNum[i]= num[i];
}
}
int trash1[]= new int[size];
int trash2[]= new int[size];
for(int i =0; i < size; i++){
if(newNum[i]>= start && newNum[i]<= end){
trash1[i]= newNum[i];
start++;
} else {
trash2[i]= newNum[i];
}
}
int sum =0;
for(int i =0; i < size; i++){
sum += trash2[i];
}
System.out.println(sum);
}
}
"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!