如何在java中使用goto语句..
package test;
import java.util.Scanner;
public class PrimeComposite {
public static void main(String[] args) {
int n,r;
Scanner input = new Scanner(System.in);
System.out.print("Ener a number: ");
n= input.nextInt();
for (int i=2; i<=n; i++){
r= n%i;
if (r==0){
System.out.print("The number is composite");
goto a: //want to jump from this loop to the a: label.
}
System.out.print("The number is prime");
}
a: //want to jump here if the if condition gets true...
}
}
答案 0 :(得分:0)
Java中没有goto
语句。只保留一个字。