Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PE #6
//Title of this code //'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_45 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int sumsq = 0; int sumsum = 0; int answer = -1; //The sum of the squares of the first 100 natural numbers for (int i =0; i<101; i++) { sumsq+= i*i; //System.out.println("Diag1. i: "+i+", sumsq: "+sumsq); } System.out.println("The sum of the squares of the first 100 natural numbers: "+sumsq); //The square of the sum of the first 100 natural numbers is for (int i=0; i<101; i++) { sumsum += i; } sumsum = sumsum * sumsum; System.out.println("The square of the sum of the first 100 natural numbers is: "+sumsum); answer = sumsum - sumsq; System.out.println("Answer: "+answer); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
om using stars
prime numbers
Java tree
thư viện
Sourab Ghosh @ IP Address
This code is not what it seems...
Integer to English Words
Coding Challenge - 02 (Odd numbers)
1.6
3d
Please log in to post a comment.