Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 24th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.Scanner;
  2.  
  3. public class PuhelinOhjelma {
  4.  
  5.         Scanner input = new Scanner(System.in);
  6.  
  7.         public void aja()
  8.         {
  9.         String numero = " ";   
  10.        
  11.         while(!numero.matches("[+]?\\d{6,15}"))
  12.         {      
  13.                 System.out.println("Anna puhelinnumero:");
  14.        
  15.                 numero = input.nextLine();
  16.                
  17.  
  18.                 if (numero.matches("[+]?\\d{6,15}")){
  19.                         System.out.println(numero + " Kelpaa");
  20.                 break; 
  21.                 }
  22.        
  23.                 else{
  24.                         System.out.println(numero + " Ei kelpaa, tarkista numero");
  25.         return numero;
  26.        
  27.                 }
  28.                 }
  29.         }
  30.  
  31.         public static void main(String[] args) {
  32.                 // luokan nimi muuttuja = new luokan nimi ();
  33.                 PuhelinOhjelma ohjelma = new PuhelinOhjelma();
  34.                 // kutsutaan luokan aja-metodia
  35.                 ohjelma.aja();
  36.         }
  37. }