joseleonweb

Untitled

Sep 21st, 2019
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. //Un programa en què cal endevinar un nombre.
  3.  
  4. public class EndevinaControlErrorsEntrada {
  5.     //PAS 1
  6.     //El nombre per endevinar serà el 4.
  7.     public static final int VALOR_SECRET = 4;
  8.     public static void main (String[] args) {
  9.         Scanner lector = new Scanner(System.in);
  10.         System.out.println("Comencem el joc.");
  11.         System.out.print("Endevina el valor enter, entre 0 i 10: ");
  12.         boolean tipusCorrecte = lector.hasNextInt();
  13.         if (tipusCorrecte) {
  14.             //S’ha escrit un enter correctament. Ja es pot llegir.
  15.             int valorUsuari = lector.nextInt();
  16.             lector.nextLine();
  17.             if (VALOR_SECRET == valorUsuari) {
  18.                 System.out.println("Exacte! Era " + VALOR_SECRET + ".");
  19.             } else {
  20.                 System.out.println("T’has equivocat!");
  21.                 } 21 System.out.println("Hem acabat el joc.");
  22.         } else {
  23.             //No s’ha escrit un enter.
  24.             System.out.println("El valor introduït no és un enter.");
  25.         }
  26.     }
  27. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×