Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
Never
import java.io.EOFException;
import java.util.Scanner;

public class Main {
    static int function(int x, int y) {
        return (int) (Math.pow(2, x) * (2 * y + 1) - 1);
    }

    static int function2(int x) { //trb modificata functia asta
        System.out.println("aici rezolvi ecuatia");
        return -1;
    }

    public static void main(String[] args) {
        ;
        //function=2^x(2*y+1)-1
        String x, y;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter two numbers: ");
        //read the strings
        x = input.next();
        y = input.next();

        //convert the strings to integers
        int x1 = Integer.parseInt(x);
        //try catch to catch the exception
        try {
            //daca nu e numar intreg arunca exceptie si se executa catch ul
            int y1 = Integer.parseInt(y);
            System.out.println("The result is: " + function(x1, y1));
            
        } catch (Exception e) {
            //if the exception is caught, the function2 is called
            function2(x1);
        }
        int y1 = Integer.parseInt(y);
    }
}