NoNameCracksInc

Java calculator

Feb 13th, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. In Slovak Language.
  2.  
  3. import java.util.*;
  4. import java.io.* ;
  5.  
  6. class start {
  7.    static String again;
  8.    static int div;
  9.   public static BufferedReader reader;
  10.   public static void main (String args[]) throws IOException {
  11.   reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.        do {
  14.  
  15.       System.out.println("Vlozte (1) pre numericku kalkulacku, (2) pre euro kalkulacku:");
  16.         String decision = reader.readLine();
  17.          int decision2 = Integer.parseInt(decision);
  18.          if(decision2 == 1) {
  19.          System.out.println('\n' + "Vybrali ste si numericku kalkulacku.");
  20.  
  21.       System.out.println("Vloz prve cislo:");
  22.       String num1 = reader.readLine();
  23.       int n1 = Integer.parseInt(num1);
  24.  
  25.         System.out.println("Vyber si operaciu:");
  26.           String op1 = reader.readLine();
  27.           char op2 = op1.charAt(0);
  28.              
  29.           System.out.println("Vloz druhe cislo:");
  30.             String num2 = reader.readLine();
  31.             int n2 = Integer.parseInt(num2);
  32.  
  33.        
  34.       try {          
  35.           if (op2 == '+') {
  36.             int plus;
  37.             plus = n1+n2;
  38.             System.out.println('\n'+ "Sucet je: " + plus);
  39. }
  40. }
  41.       catch(ArithmeticException v) {
  42.             System.out.println("Chyba: " + v.getMessage());
  43. }
  44.       try {
  45.           if (op2 == '-') {
  46.             int minus;
  47.             minus = n1-n2;
  48.             System.out.println('\n'+ "Rozdiel je: " + minus + ".");
  49. }
  50. }
  51.       catch (ArithmeticException v) {
  52.              System.out.println("Chyba: " + v);
  53. }
  54.       try {
  55.           if (op2 == '*') {
  56.             int mult;
  57.             mult = n1*n2;
  58.             System.out.println('\n'+ "Sucin je: " + mult + ".");
  59. }
  60. }
  61.       catch (ArithmeticException v) {
  62.              System.out.println("Chyba: " + v);
  63. }
  64.       try {
  65.           if (op2 == '/' && n2 == 0)
  66.             throw new ArithmeticException ("Delenie nulou.");  
  67.           if (op2 == '/' && n2 != 0) {
  68.              div = n1/n2;
  69.             System.out.println('\n'+ "Podiel je: " + div + ".");          
  70.            
  71. }
  72. }
  73.       catch (ArithmeticException v) {
  74.              System.out.println("Chyba: " + v.getMessage());
  75. }
  76. }
  77. if (decision2 == 2) {
  78.   System.out.println('\n' + "Vybrali ste si euro kalkulacku.");
  79.   System.out.println("Vlozte pocet eur: ");
  80.     String euro = reader.readLine();
  81.     int euro2 = Integer.parseInt(euro);
  82.  
  83. try {
  84.     if (euro2 == 0 || euro2 > 4)
  85.   System.out.println(euro2 + " eur je priblizne " + euro2*30 + " korun.");
  86.     if (euro2 == 1)
  87.   System.out.println(euro2 + " euro je priblizne " + euro2*30 + " korun.");
  88.     if (euro2 == 2 || euro2 == 3 || euro2 == 4)
  89.   System.out.println(euro2 + " eura su priblizne " + euro2*30 + " korun.");
  90. }
  91. catch (ArithmeticException v) {
  92.   System.out.println("Chyba: " + v);
  93. }
  94. }
  95.    System.out.println('\n' + "Spustit znova? y/n");
  96.    again = reader.readLine();
  97. }
  98.  
  99.    while(!again.equals("n"));
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment