-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigO_N
30 lines (24 loc) · 934 Bytes
/
BigO_N
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bigo_n;
public class BigO_n {
public static void main(String[] args) {
int s1_steps = 0, s2_steps= 0, s3_steps = 0;
int N;
System.out.print("Enter an integer value for N: ");
N = new java.util.Scanner(System.in).nextInt(); //look-anonymous object
int s = 0; s1_steps++; //s1
s2_steps++;
for (int i=1; i<=N; s2_steps++, i++) //s2
{
s = s+i;
s3_steps++; //s3
}// end for loop
System.out.printf("S1 executed %d times %n", s1_steps);
System.out.printf("S2 executed %d times %n", s2_steps);
System.out.printf("S3 executed %d times %n", s3_steps);
}//end main method
}