Advertisement
_srdja_

prob2-3

Feb 8th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static int produkt(int n1, int n2) {
  7.         return n1 * n2;
  8.     }
  9.    
  10.     public static int potenca(int n) {
  11.         return (int) Math.pow(n, 5);
  12.     }
  13.    
  14.     public static void main(String[] args) {
  15.         Scanner s = new Scanner(System.in);
  16.        
  17.         int a;
  18.         int b;
  19.         int c;
  20.                
  21.         System.out.println("Enter value of a (1-9): ");
  22.         while ((a = s.nextInt()) < 1 || a > 9) {
  23.             System.out.printf("%d is out of range (1-9)\n Please try again:\n", a);
  24.         }
  25.        
  26.         System.out.println("Enter value of b (1-9): ");
  27.         while ((b = s.nextInt()) < 1 || b > 9) {
  28.             System.out.printf("%d is out of range (1-9)\n Please try again:\n", b);
  29.         }
  30.        
  31.         System.out.println("Enter value of c (1-9): ");
  32.         while ((c = s.nextInt()) < 1 || c > 9) {
  33.             System.out.printf("%d is out of range (1-9)\n Please try again:\n", c);
  34.         }
  35.                
  36.         s.close(); 
  37.                
  38.         System.out.println("Product of 'a' and 'b' = " + produkt(a, b));
  39.         System.out.println("Product of 'a' and 'b' = " + produkt(a, c));
  40.         System.out.println("Product of 'a' and 'b' = " + produkt(b, c));
  41.        
  42.         System.out.println("a^5 = " + potenca(a));
  43.         System.out.println("b^5 = " + potenca(b));
  44.         System.out.println("c^5 = " + potenca(c));
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement