How to use/check for String variables in the Scanner using Java Neon Eclipse

Pubblicato il: 17 gennaio 2017
sul canale di: Minute Coding
788
5

The purpose of this video is to demonstrate the method and variables required to check/validate a string the user entered using the Scanner. Additionally, it covers how we can check for integers.

Please note: I did not optimize the questionnaire (i.e. There isn't a looping function to go back if there is incorrect data).

Here is the code if you wish to copy and paste it:

import java.util.Scanner;

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

System.out.println("What's your name?");

String name = input.nextLine();
if (name.equals("Claire"))
{
System.out.println("How old are you?");

int age = input.nextInt();
if (age !=22)
{
System.out.println("Thank you for your time.");
}

else
{
System.out.println("This was a pointless questionaire, thank you.");
}



}
else
{
System.out.println("Leave");
}
}
}


In questa pagina del sito puoi guardare il video online How to use/check for String variables in the Scanner using Java Neon Eclipse della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Minute Coding 17 gennaio 2017, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 788 volte e gli è piaciuto 5 spettatori. Buona visione!