Java if(是或否声明) [英] Java if (Yes or No Statement)

查看:303
本文介绍了Java if(是或否声明)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的java代码遇到了一些问题。
我尝试用Java编写一些代码几个小时,我不知道这就是为什么我要问。我通过尝试学得最好,但是我遇到了很多问题。

Hey there I got into some trouble with my java Code. I try to code a bit around with java for a few hours and I dont know much thats why im asking. I learn best by trying but I get into so many problems.

所以:我希望扫描仪扫描下一个语句,如果它的ja它应该执行if事情等。

So: I want the scanner to scan the next Statement and if its "ja" it should do the if thing etc.

问题是,当我尝试编译它时,它与= s.nextInt事件有错误。在控制台中它说:找不到符号。我尝试了很多我不知道该怎么做的事情。已经尝试了很多。

The problem is, when i try to compile it it has an error with the = s.nextInt thing. In the console it says: "cannot find symbole". I tried so many things I dont know what to do. Allready tried so much.

import java.util.Scanner;

public class Brotcrunsher {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        System.out.println ("Hallo");
        System.out.println ("A flag has more then 1 color right?");
        String a = s.NextInt();
        if (a.equals("ja")) {
            System.out.println ("You arent dumb, nice.");
        } // end of if
        else {
            System.out.println ("You arentn a genie");
        } // end of if-else
    }
}

提前谢谢。

编辑:问题解决了。谢谢你的每一个人。我尽力更好地标记我的帖子并更好地格式化我的代码

Problem solved. Thank you for every awnser. I try my best to Tag my posts better and to format my code better

推荐答案

尝试:

import java.util.Scanner;
public class Brotcrunsher {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        System.out.println ("Hallo");
        System.out.println ("A flag has more then 1 color right?");

        String a = scan.nextLine();
        if (a.equals("ja")) {
            System.out.println ("You arent dumb, nice.");
        } // end of if
        else {
            System.out.println ("You arentn a genie");
        } // end of if-else
    }
}

这篇关于Java if(是或否声明)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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