Given this piece of Java code:
import java.util.Scanner;
class BreakWhileLoop {
public static void main(String[] args) {
int n;
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("Input an integer");
n = input.nextInt();
if (n == 0) {
break;
}
System.out.println("You entered " + n);
}
}
}
Take this particular case the user will always enter any integer except 0.
1. Can I consider this code as an algorithm?
2. If yes, how to calculate its complexity?
thank
source
share