Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Komentotulkki3 {
  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;
  13.                 do {
  14.                         komento = lueKomento();
  15.                         boolean a;
  16.                         a = komento.equals("fibo") && fibo();
  17.                         a = komento.equals("kerto") && kerto();
  18.                         a = komento.equals("pii") && pii();
  19.                 } while (komento.equals("fibo") ||
  20.                          komento.equals("kerto") ||
  21.                          komento.equals("pii"));
  22.         }
  23.  
  24.         public static String lueKomento() {
  25.                 System.out.print("> ");
  26.                 return lukija.nextLine();
  27.         }
  28.  
  29.         public static boolean fibo() {
  30.                 int a = 0, b = 1, c;
  31.                 System.out.println(a);
  32.                 System.out.println(b);
  33.                 for (int i = 0; i < 8; i++) {
  34.                         c = a; a = b; b = b + c;
  35.                         System.out.println(b);
  36.                 }
  37.                 return true;
  38.         }
  39.  
  40.         public static boolean kerto() {
  41.                 for (int i = 1; i <= 10; i++) {
  42.                         for (int j = 1; j <= 10; j++) {
  43.                                 int k = i * j;
  44.                                 if (k < 10) System.out.print(" ");
  45.                                 if (k < 100) System.out.print(" ");
  46.                                 System.out.print(" " + k);
  47.                         }
  48.                         System.out.println();
  49.                 }
  50.                 return true;
  51.         }
  52.  
  53.         public static boolean pii() {
  54.                 System.out.println(Math.PI);
  55.                 return true;
  56.         }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement