joseleonweb

Untitled

Sep 21st, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. //Anem a llegir un enter entre 0 i 10.
  4. public class ValorFitat {
  5.     public static void main (String[] args) {
  6.         Scanner lector = new Scanner(System.in);
  7.         int valorUsuari = 0;
  8.         do {
  9.             //PAS 1 i 2: Com a mínim, segur que es pregunta un cop.
  10.             System.out.print("Introdueix un valor enter entre 0 i 10: ");
  11.             valorUsuari = lector.nextInt();
  12.             lector.nextLine();
  13.             //PAS 3: Només té sentit avaluar si ’valor’ és vàlid un cop s’ha llegit.
  14.         } while ((valorUsuari < 0)||(valorUsuari > 10));
  15.         //PAS 4: Tot correcte
  16.         System.out.println("Dada correcta. Has escrit " + valorUsuari);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment