Question

ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is,...

ANSWER USING JAVA CODE

(1)The sum of the squares of the first ten natural numbers is,

12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + ... + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

(2) Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.

What is the total of all the name scores in the file?

(3) A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc.

(4)If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

(5)The following iterative sequence is defined for the set of positive integers:

n → n/2 (n is even)

n → 3n + 1 (n is odd)

Using the rule above and starting with 13, we generate the following sequence:

13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

NOTE: Once the chain starts the terms are allowed to go above one million.


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

import java.io.*;

class Main {

static int squaresum(int n) // called function

{

int square_sum = 0; // variable declaration

for (int i = 1; i <= n; i++) // Loop runs from 1 through n

square_sum += (i * i); // calculate square sum

return square_sum; // return  square sum

}

static int sumsquare(int n) // called function

{

int sum_square = 0; // variable declaration

for (int i = 1; i <= n; i++) // Loop runs from 1 through n

sum_square += i; // calculate sum of n numbers

sum_square*=sum_square; // calculate sum square

return sum_square;    // return sum square

}


public static void main(String args[]) throws IOException

{

int n = 100,a,b,difference; // variable declaration

a=squaresum(n); // calling function

b=sumsquare(n); // calling function

difference=b-a; // Find difference between the sum of the squares of the first one hundred natural numbers and the square of the sum

System.out.println("\nSum of the squares of the first 100 natural numbers "+a);

System.out.println("\nSquare of the sum of first 100 natural numbers "+a);

System.out.println("\nDifference between the sum of the squares of the first one hundred natural numbers and the square of the sum is "+difference);

}

}

Output:

According to HomeworkLib guidelines i have to solve first question only. Please do next post for remaining answers.

Add a comment
Know the answer?
Add Answer to:
ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT