
Can you please Explain the following code :
import java.util.*; class Difference { public static void main(String args[]) { int n,i,res=0,sum=0,dif; System.out.println("Enter the number"); Scanner in= new Scanner(System.in); n=in.nextInt(); for(i=1;i<=n;i++) res=res+i; res=res*res; for(i=1;i<=n;i++) sum=sum+i*i; if(sum>res) dif=sum-res; else dif=res-sum; System.out.println("Result:"+dif); } }
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.