Advertisement
Guest User

Untitled

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