Java中if/else的具体用法是什么?(可以具体到代码吗?)非常感谢!

问题遇到的现象和发生背景

java里if else 的用法是咋用的?

问题相关代码,请勿粘贴截图
    Scanner sc=new Scanner(System.in);
    System.out.print("输入n:");
    int n= sc.nextInt();
    Scanner sc1=new Scanner(System.in);
    System.out.print("输入x:");
    int x= sc1.nextInt();
    int y=1;
    int i=n-1;
    if (i>=0){
        y=x*y+i;
        i=i-1;
    }
    else {
        System.out.print("y为:");
    }
运行结果及报错内容

输入n=3和x=3后的y值没有输出结果。

输入N,假设N=3,i = N - 1也就是=2,此时你可以看成if(2 >= 0)所以这个if语句是成立的,输出不了y,想要输出y,此时N要至少等于0

i在第8行被赋值为2,满足i>.=0,执行if语句(执行9-12行),13-15行不执行,因此没有输出结果

你的if写的是i>=0,当你输入n=3时,进入if,当你输出n=0时,进入else

Scanner sc = new Scanner(System.in);
        System.out.print("输入n:");
        int n = sc.nextInt();

        Scanner sc1 = new Scanner(System.in);
        System.out.print("输入x:");
        int x = sc1.nextInt();

        int y = 1;
        int i = n - 1;

        if (i >= 0) {
            y = x * y + i;
            System.out.print("进入if,y为:" + y);
        } else {
            System.out.print("进入else,y为:" + y);
        }

Scanner sc = new Scanner(System.in);
        System.out.print("n:");
        int n = sc.nextInt();
 
        Scanner sc_= new Scanner(System.in);
        System.out.print("x:");
        int x = sc_.nextInt();
 
        int y = 1;
        int i = n - 1;
 
        if (i >= 0) {
            y = x * y + i;
            System.out.printf("y=%d" + y);
        } else {
            System.out.printf("y=%d" + y);
        }