编译器说Java代码无效 [英] Compiler says Java code is invalid

查看:96
本文介绍了编译器说Java代码无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理Java代码:

I am working on a Java code:

import java.util.Scanner;

public class main
{
    static Scanner console = new Scanner (System.in);
    public static void main (String aurgs[]) {

        System.out.print("Which function would you like to vist? L for Lottery, R for Random Math");
        char lotto = 'l';
        char rdm = 'b';

        if (console.nextChar() = lotto) /**error is here*/ {
            lottery();
        }
    }
    public static void lottery (String aurgs[]) {
        String announ = "Your lottery numbers for today are: ";
        System.out.print(announ);
        int [] numbers = {15, 68, 25, 66};
        double lucky = 50.2;
        for (int i: numbers )
            System.out.print(i + "\n");

        String announ2 = "Your lucky number is: ";
        System.out.println(announ2 + lucky);
        }
}

当我编译它时,BlueJ说:

When I compile it, BlueJ says:

找不到符号-方法nextChar()

我不明白怎么了.

推荐答案

Scanner类没有nextChar()方法.在此处列出了所有可用的方法, nextChar().您可以改用next()并将单个字符读取为字符串.

The Scanner class has no nextChar() method. The methods available are listed here, none of which are nextChar(). You can instead use next() and read a single character as a string.

这篇关于编译器说Java代码无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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