-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranscation.java
34 lines (34 loc) · 942 Bytes
/
Transcation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
class Transaction {
public static void main(String args[]) throws Exception {
Scanner s = new Scanner(System.in);
System.out.println("enter the size of transaction array");
int size = s.nextInt();
int arr[] = new int[size];
System.out.println("enter the values of array");
for (int i = 0; i < size; i++)
arr[i] = s.nextInt();
System.out.println("enter the total no of targets that needs to be achieved");
int targetNo = s.nextInt();
while (targetNo-- != 0) {
int flag = 0;
long target;
System.out.println("enter the value of target");
target = s.nextInt();
long sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
if (sum >= target) {
System.out.println("Target achieved after "+(i + 1) + "
transactions ");
flag = 1;
break;
}
}
if (flag == 0) {
System.out.println(" Given target is not achieved ");
}
}
}
}
--------------------------------------------------------------------