0
So I have a code that takes input that's an int but it keeps giving me "error: incomparable types scanner and int" how do I fix?
Code error
7 Antworten
+ 3
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
System.out.println(x + 2);
+ 1
I think you have to put the .nextInt() on another variable, because the your "MyVar" is a instance of a Scanner.
Scanner myVar = new Scanner(System.in);
int numLine = myVar.nextInt();
if (...
+ 1
Sorry I've forgot something. Use the method .nextLine and use a Integer.parseInt() to convert the value.
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int value = Integer.parseInt(sc.nextLine());
System.out.println(value);
}
}
*But, I can run the code without that conversion
+ 1
Sure. Consider voting for me :)
0
See my code is import java.util.*;
import java.lang.*;
import java.util.Scanner;
class Rextester
{
public static void main(String args[])
{
int num=7;
Scanner myVar = new Scanner(System.in);
System.out.println(myVar.nextint());
if (myVar ==num ) {
System.out.println("AHHHHH BOOOIIIIII");
}else if (myVar!=num) { System.out.println("no wrong");
}
else { System.out.println("idek");}
}
}
0
Sadly has not worked either
0
Oh this worked. Thanks so much!