编译错误:预期的标识符 [英] compilation error: identifier expected

查看:531
本文介绍了编译错误:预期的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.io.*;

public class details
{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("What is your name?");
    String name = in.readLine(); ;
    System.out.println("Hello " + name);
}

我的代码问题是我在编译时得到标识符。 。
谁能帮助我做什么?
或更好,任何人都可以提供使用BufferedReader提示名称,地址和年龄的代码,然后最终显示输出..

my problem with this code is that i get " identifier expected " when compiling.. can anyone help me on what to do? or better, can anyone provide the code that would use BufferedReader to prompt the name, address, and age then finally would display the output..

谢谢! !

推荐答案

您尚未定义代码周围的方法。

You have not defined a method around your code.

import java.io.*;

public class details
{
    public static void main( String[] args )
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("What is your name?");
        String name = in.readLine(); ;
        System.out.println("Hello " + name);
    }
}

在这种情况下,我假设你想要你的要在类的 main 方法中执行的代码。当然,这个代码可能采用任何其他方法。

In this case, I have assumed that you want your code to be executed in the main method of the class. It is, of course, possible that this code goes in any other method.

这篇关于编译错误:预期的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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