public class Main {
public static void main(String[] args) {
System.out.println((char)65); // 'A'
System.out.println((char)(65+1)); // 'B'
System.out.println((char)(65+2)); // 'C'
System.out.println((char)(65+3)); // 'D'
System.out.println((int)'z'); // 122
}
}
public class HelloWorld {
public static void main(String []args){
sayHello(5);
System.out.println(add(4, 5));
}
public static void sayHello(int nTimes) {
for (int i = 0; i < nTimes; i++) {
System.out.println("Hello");
}
}
public static int add(int x, int y) {
return x+y;
}
}
Declare a method that prints array given as a parameter.
Create a new method, which returns a randomly generated integer array.
Write a method, which creates a clone of a given char array (same size and same content).
Create a method: mergeTwoArrays. It takes 2 arrays and returns a new one, what is a join result of them.
i.e.: [1,2]+[2,3,4]=[1,2,2,3,4]
Create a new method, which returns sum of all values in a given array. Use the method in main.
Create a new method, which prints two values from an array, which sum is the nearest to 0. Use the method in main.
Create a new method, which returns array with elements with reversed order. Use the method in main.
There are two arrays (arr1 and arr2) filled in with random integer numbers. Write a program which:
Write a method that generates random array of integers (20 elements) and prints its content without repetition of elements.
Write a method that generates random array of integers (200 elements) and prints its the most common element.
Pass null as a value for array to call any method.
Create a method that multiplies every element of copied array by a given number.
Read about Fibonacci sequence. Display n-th number of the sequence without using any loop. Tip: call a method in the same method.
Display an array without using any loop, nor ready to use methods of Java Api.
Using task 12. code, calculate 1000th Fibonacci number. Then create an implementation with any loop and compare it with recursion.
Create methods (to make main working):
For encrypting you can create your own formula or use existing one (for example: Caesar cipher).
It is forbidden to modify main method.
public class PointedTask2019Edition {
public static void main(String[] args) {
int arraySize = 100;
int[] model = generateRandomArray(arraySize);
int[] clone = copyArray(model);
if (areArraysEqual(model, clone))
System.out.println("I score 1 point");
else
System.out.println("Something is wrong");
int[] merged = mergeTwoArrays(model, clone);
if (merged.length == arraySize*2)
System.out.println("I score 1 point");
else
System.out.println("Something is wrong");
char from = 'a';
char to = 'z';
char[] message = generateRandomMessage(arraySize, from, to);
char[] encrypted = encrypt(message);
System.out.print("Encrypted: ");
printArray(encrypted);
char[] decrypted = decrypt(encrypted);
System.out.print("Decrypted: ");
printArray(decrypted);
if (areArraysEqual(message, decrypted))
System.out.println("Maybe I score 3 points");
else
System.out.println("Maybe I score 0, 1, 2 points...");
}
// tip: start here
}