vendredi 31 janvier 2020

Why if condition "(skaner.next() != int)" highlights as wrong?

I wanna make a condition if somebody input a word the program will return "That is a string" if it is an integer the program will return "That is an integer ". What's wrong with my if condition ?

package folder;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    Scanner skaner = new Scanner(System.in);

    while (skaner.hasNext()){
        if (skaner.next() != int) {
            System.out.println("That is a string" + skaner.next());
        }
        else {
            System.out.println("That is an integer " + skaner.next());
        }
    }
    skaner.close();


    }
}

Aucun commentaire:

Enregistrer un commentaire