+ 4
HELP ME PLEASE
import java.util.Scanner; public class Program { public static void main(String[] args) { char x; Scanner s = Scanner(System.in); x = s.next().charAt(0); switch(x) { case 't': System.out.Println("You found the Letter! Congrats, thanks for playing! Be sure to Upvote!"); break; default: System.out.println("Error not correct letter."); } } }
4 Respostas
+ 5
* Scanner s = new Scanner (System.in);
*String x;
* x = s.next (); //next () and nextLine () expect a String (char is not possible)
* case "t": //because x is String
* System.out.println ("You found...);
Now it should work.
+ 2
You can see the correct code here. Hope it helps you.
https://code.sololearn.com/c4esJGc0mFfm/?ref=app
+ 1
You can use char type as well.
You made just two errors in your code:
- at line 6 you forgot new keyword to make a new Scanner object
- and at line 11 you have typo Println instead of println.
And that is all :-)
https://code.sololearn.com/c9g41gKiWsRN/?ref=app
0
I would honestly avoid to use the switch statement...here it is my code which I hope that gives the same result you expected:
//My Program
import java.util.Scanner;
public class Program {
private static Scanner in;
public static void main(String[] args) {
in = new Scanner(System.in);
String x = in.next();
if(x.equalsIgnoreCase("t"))
{System.out.println("Found....");}
else{System.out.println("Error....");}
}
}