Modular Calculator in java

Back to Problem Solutions forum

Azizbek_D     2020-11-03 14:18:09

long n=sc.nextLong(); long m; String s; int u=0; do{ s=sc.next(); m=sc.nextLong(); if(s.equals("+")) n=n+m; else if(s.equals("")) n=nm;

    }while(!s.equals("%")); 
    System.out.println(n%m+" ");


    I didn’t know where the error was. Please help me
Rodion (admin)     2020-11-04 07:57:57
User avatar

Hi Azizbek!

This task is specially invented to teach people avoid some common mistake. So it would be much better if you could find this mistake yourself :)

I recommend to add printing of n on every iteration, so you can easily see when mistake happens.

Please login and solve 5 problems to be able to post at forum