I'm new to Java. I want to get loop input except when the user inputs 0 that terminates the program in Java. I know how to implement this in C++ (as shown below), but the Java code I wrote doesn't work.
C++:
while (cin >> n, n) {
GraphAdjList G;
CreateAdjListGraph(G, n);
n = 0;
}
Java:
Scanner sc = new Scanner(System. in );
n = sc.nextInt();
while (n != 0) {
Graph G = new Graph();
G.CreateAdjListGraph(n);
//G.print();
n = sc.nextInt();
}
This is what I want. The program terminates only when the user inputs 0.
2
qRj dIm
aTy oFu
4
qRj aTy
qRj oFu
oFu cLq
aTy qUr
0