Skip to content

Instantly share code, notes, and snippets.

@Shubhra22
Last active October 31, 2020 19:27
Show Gist options
  • Save Shubhra22/464410bf0347a1873693a395b1260073 to your computer and use it in GitHub Desktop.
Save Shubhra22/464410bf0347a1873693a395b1260073 to your computer and use it in GitHub Desktop.

Problem 1

Fermat’s Last Theorem says that there are no integers a, b, and c such that an + bn = cn, except when n ≤ 2.

Write a method named checkFermat that takes four integers as parameters – a, b, c and n – and checks to see if Fermat’s theorem holds. If n is greater than 2 and an + bn = cn, the program should display “Holy smokes, Fermat was wrong!” Otherwise the program should display “No, that doesn’t work.” Hint: You may want to use Math.pow.

Problem 2

The goal of this exercise is to program a “Guess My Number” game. When it’s finished, it will work like this:

I'm thinking of a number between 1 and 100.
(including both). Can you guess what it is?
Type a number: 45.
Your guess is: 45.
The number I was thinking of is: 14.
You were off by: 31.

Hint: You need to use the Random method comes with java. for this we will need to import the random.util class

 import java.util.Random; 

and then to create a random number between 1 to 100 you do:

 
 Random rand = new Random(); //instance of random class
 int upperbound = 100;
 //generate random values from 0-100
 int int_random = rand.nextInt(upperbound);  

Problem 3

Take input from the user = x and n.
You can assume that n is always even Then calculate the folling series. 1+ x 2 + x 4 + x 6 + x 8 + ...... + x n

Problem 4

Write a program in Java to display the n terms of odd natural number and their sum

Problem 5

The Fibonacci sequence is a series of numbers where a number is the addition of the last two numbers, starting with 0, and 1.
for example the first few numbers are 0 1 1 2 3 5... if u look closely, the sum of first two number forms the third, the sum of 2nd and 3rd number forms 4th and so on...

Write a program that shows n fibonacci numbers

Print out the following patterns
*
**
***
****
*****
* * * *
* * * *
* * * *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment