首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Delete Delete语句,但需要else语句

Delete Delete语句,但需要else语句
EN

Stack Overflow用户
提问于 2014-10-10 17:23:24
回答 1查看 105关注 0票数 0

基本上,我是在做一个java教程,但是为了继续下去,我需要创建一个类文件。所有的东西都给了我,但它给了我一个错误。错误是:删除else语句或类似的内容。但是当我删除它时,它告诉我要在那里放另一条语句。

代码是:这是eclipse的问题还是代码有问题?

代码语言:javascript
复制
import java.io.*;
import java.text.*;
public class In {
    static InputStreamReader r = new InputStreamReader(System.in);
    static BufferedReader br = new BufferedReader(r);
    // Read a String from the standard system input
    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
            return "";
        }
    }
    // Read a number as a String from the standard system input
    // and return the number
    public static Number getNumber() {
        String numberString = getString();
        try {
            numberString = numberString.trim().toUpperCase();
            return NumberFormat.getInstance().parse(numberString);
        } catch (Exception e)

        {
            // if any exception occurs, just return zero
            return new Integer(0);
        }
    }
    // Read an int from the standard system input
    public static int getInt() {
        return getNumber().intValue();
    }
    // Read a long from the standard system input
    public static long getLong() {
        return getNumber().longValue();
    }
    // Read a float from the standard system input
    public static float getFloat() {
        return getNumber().floatValue();
    }
    // Read a double from the standard system input
    public static double getDouble() {
        return getNumber().doubleValue();
    }
    // Read a char from the standard system input
    public static char getChar() {
        String s = getString();
        if (s.length() >= 1)
            return s.charAt(0);
        else
            return’\ n’;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-10 17:58:53

造成错误的是,不管你周围有什么乱七八糟的标记\n都不是撇号.我不知道他们是什么。在完全按照您的方式重写代码之后,除了用撇号(加上在if和were语句中使用大括号,因为我更喜欢那样)之外,没有出现错误:

代码语言:javascript
复制
public static char getChar ()
{
    String s = getString();
    if (s.length() >= 1){
        return s.charAt(0);
    }else{
        return '\n';
    }
}

在将来,请确保在你的问题中使用正确的缩进,使我们更容易阅读。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26304819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档