Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Komentotulkki4 {
- public static Scanner lukija = new Scanner(System.in);
- public static boolean tulkki(String komento) {
- boolean a = ((komento.equals("fibo") && fibo() && tulkki(lueKomento())) ||
- (komento.equals("kerto") && kerto() && tulkki(lueKomento())) ||
- (komento.equals("pii") && pii() && tulkki(lueKomento())));
- return true;
- }
- public static void main(String[] args) {
- System.out.println("Komennot:\n");
- System.out.println("fibo Fibonaccin luvut");
- System.out.println("kerto 10:n kertotaulu");
- System.out.println("pii piin likiarvo");
- System.out.println();
- tulkki(lueKomento());
- }
- public static String lueKomento() {
- System.out.print("> ");
- return lukija.nextLine();
- }
- public static boolean fibo() {
- int a = 0, b = 1, c;
- System.out.println(a);
- System.out.println(b);
- for (int i = 0; i < 8; i++) {
- c = a; a = b; b = b + c;
- System.out.println(b);
- }
- return true;
- }
- public static boolean kerto() {
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- int k = i * j;
- if (k < 10) System.out.print(" ");
- if (k < 100) System.out.print(" ");
- System.out.print(" " + k);
- }
- System.out.println();
- }
- return true;
- }
- public static boolean pii() {
- System.out.println(Math.PI);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement