Logic & Coding Array Lab
Write a program that solves these multiple problems/tasks.
Baby's First Array
1. Write a program that takes an array of integers and it increments each value by 1.
For example, an array with values {1, 2, 3, 4 -3} = {2, 3, 4, 5, -2}
Jury-Rigged Fibonacci Sequence
2. Write a program that takes an EMPTY array of integers with the first two spaces
containing a number, like so: {4, 16, BLANK, BLANK, BLANK, etc.} and then fills up
the remaining spaces of the array using the fibonacci sequence, with the first two
numbers of the array being Xn-1 and Xn-2.
(Fibonacci Sequence: Xn = Xn-1 + Xn-2)
Example of a finalized array with 10 spaces: {5, 3, 8, 11, 19, 30, 49, 79, 128, 207}
The Sieve of Eratosthenes
3. Write a program that inputs all of the prime numbers from 2 - 10000.
You will need an array filled with prime numbers (in order) for the next problem.
Sift the twos, sift the threes-
The Sieve of Eratosthenes!
When the multiples sublime
The numbers that remain are prime!
Translation:
1. Strike out 0 and 1.
2. Let n = 2
3. Strike out all multiples of n greater than n
4. Add one to n
5. Repeat steps 3 and 4 until n is greater than
the last number in the array
6. Stop. The remaining numbers are prime.
Prime Factorization
4. Given an array with prime numbers, create a program that returns the
PRIME factorization of a given number.
Ex: Prime factorization of 132
2: 2
3: 1
11: 1
2*2*3*11 = 132
BIG Int Notation
5. Java has a limit on the size of numbers that it can represent as the int type:
ints may be from -2,147,483,648 to 2,147,483,647 inclusive. (That is horrible)
I want this fixed. One way of getting around this disgusting limitation
is through arrays! Let each int in an array represent a digit of a large number.
This is an open ended question, where you get to design the functionality
of your array number. Here are some questions to help guide you:
1. How will you implement negative numbers?
2. How will you compare numbers to see which one is greater or lesser?
3. How will you implement addition and subtraction with your array numbers?
Your code should be able to handle a value such as -345938007483190297389128290
storing it properly and being able to do simple addition/subtraction with it.
import java.util.Scanner;
import java.util.Random;
public class arraylab
{
public static void main(String[] args)
{
// Out of bounds!!!
//Your scanner initialized
Scanner myScanner = new Scanner(System.in);
//Out of bounds!!!
}
}