java 跳出否,Java if(是或否声明)

博主在尝试用Java编程时遇到了Scanner读取输入的问题,具体表现为编译错误提示“cannot find symbol”。在代码中,博主试图通过Scanner读取用户输入的字符串并进行条件判断。经过讨论和编辑,问题得到了解决,原来是使用了nextInt()而不是nextLine()来读取字符串。修改后的代码成功运行,实现了预期的功能,即根据用户输入的'ja'执行不同的输出语句。
摘要由CSDN通过智能技术生成

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.

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

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

}

}

thanks in advance.

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

解决方案

Try:

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

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值