Run Code
|
API
|
Code Wall
|
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
OurDate.java
simple date time in java
Java For Each Loop
hondaa11
Armstrong number
Counter.java
inheritance
Huffman Encoding Tree
ArrayOperation
Sorting array