这里不允许使用JAVA变量声明 [英] JAVA Variable declaration not allowed here

查看:7028
本文介绍了这里不允许使用JAVA变量声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误此处不允许变量声明,我不知道为什么,我是java的新手并且无法找到答案:/
正如它所说,我无法制作 intinif但是有没有办法创建它?

I get an error "Variable declaration not allowed here" and I don't know why, I'm new in java and can't find answer :/ As it says, I can't make "int" in "if" but is there a way to create it?

import java.io.PrintWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;import java.util.Scanner;
 public class test{
  public static void main(String[] args) throws FileNotFoundException{
    File plik = new File("test.txt");
    PrintWriter saver = new PrintWriter("test.txt");

     int score = 0;
     System.out.println("Q: What's bigger");
     System.out.println("A: Dog B: Ant");
     Scanner odp = new Scanner(System.in);
     string odpo = odp.nextLine();

     if(odpo.equals("a"))
        int score = 1;
     else
         System.out.println("Wrong answer");

  }
}


推荐答案

string 必须更改为字符串

通过编写 int score ,您试图声明一个已存在的新变量,您已经在之前声明了该变量。只需删除 int 部分,您就可以获得所需的作业。

By writing int score you're trying to declare a new variable that already exists, which you declared before already. Just remove the int part and you will get the assignment you want.

这篇关于这里不允许使用JAVA变量声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆