我是新手这段代码编译不通过啊,求帮助。
import java.util.Scanner;
public class Fizzbuzz
{
public static void main(String[] args)
{ int a=1;
while(a==1){
Scanner scanner = new Scanner(System.in);
System.out.print("请输入整数:");
int i;i = scanner.next();
try{
i=Integer.parseInt(i);
}catch(Exception e){
System.out.println("输入有错,请重新输入:");
}
if(i%15==0)
System.out.print ("FizzBuzz");
else if(i%3==0)
System.out.print ("Fizz");
else if(i%5==0)
System.out.print ("Buzz");
else
System.out.print (i);
System.out.print("是否继续:1(是)0(否)");
a = scanner.nextInt();
}
}
}
------解决方案--------------------
- Java code
import java.util.Scanner;public class Fizzbuzz{ public static void main(String[] args) { int a=1; while(a==1){ Scanner scanner = new Scanner(System.in); System.out.print("请输入整数:"); int i =0 ; try{ i=Integer.parseInt(scanner.next()); }catch(Exception e){ System.out.println("输入有错,请重新输入:"); } if(i%15==0) System.out.print ("FizzBuzz"); else if(i%3==0) System.out.print ("Fizz"); else if(i%5==0) System.out.print ("Buzz"); else System.out.print (i); System.out.print("是否继续:1(是)0(否)"); a = scanner.nextInt();} }}