Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Komentotulkki4 {
  4.         public static Scanner lukija = new Scanner(System.in);
  5.  
  6.         public static boolean tulkki(String komento) {
  7.                 boolean a = ((komento.equals("fibo") && fibo() && tulkki(lueKomento())) ||
  8.                              (komento.equals("kerto") && kerto() && tulkki(lueKomento())) ||
  9.                              (komento.equals("pii") && pii() && tulkki(lueKomento())));
  10.                 return true;
  11.         }
  12.  
  13.         public static void main(String[] args) {
  14.                 System.out.println("Komennot:\n");
  15.                 System.out.println("fibo   Fibonaccin luvut");
  16.                 System.out.println("kerto  10:n kertotaulu");
  17.                 System.out.println("pii    piin likiarvo");
  18.                 System.out.println();
  19.                 tulkki(lueKomento());
  20.         }
  21.  
  22.         public static String lueKomento() {
  23.                 System.out.print("> ");
  24.                 return lukija.nextLine();
  25.         }
  26.  
  27.         public static boolean fibo() {
  28.                 int a = 0, b = 1, c;
  29.                 System.out.println(a);
  30.                 System.out.println(b);
  31.                 for (int i = 0; i < 8; i++) {
  32.                         c = a; a = b; b = b + c;
  33.                         System.out.println(b);
  34.                 }
  35.                 return true;
  36.         }
  37.  
  38.         public static boolean kerto() {
  39.                 for (int i = 1; i <= 10; i++) {
  40.                         for (int j = 1; j <= 10; j++) {
  41.                                 int k = i * j;
  42.                                 if (k < 10) System.out.print(" ");
  43.                                 if (k < 100) System.out.print(" ");
  44.                                 System.out.print(" " + k);
  45.                         }
  46.                         System.out.println();
  47.                 }
  48.                 return true;
  49.         }
  50.  
  51.         public static boolean pii() {
  52.                 System.out.println(Math.PI);
  53.                 return true;
  54.         }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement