Skip to content
Snippets Groups Projects
Commit d71eacaa authored by Martin Vatshelle's avatar Martin Vatshelle
Browse files

Code to be used during lecture

parent 4a7ae672
No related branches found
No related tags found
No related merge requests found
package lecture3;
import java.util.ArrayList;
/**
* This file contains sample functions we will study in order to learn about runtime analysis.
*
* @author Martin Vatshelle
*
*/
public class BigOAnalysis {
//n er lengden av numbers
public static void useList(ArrayList<Integer> numbers) {
int a = numbers.get(0);
int b = numbers.get(1);
int sum = a+b;
numbers.add(0,sum);
}
//Hva er n her?
public static void order1(int a, int b) {
int sum = a + b;
System.out.println("Summen av "+a+" + "+b+" er "+sum);
}
public static void loopDeLoop(int n) {
for(int i=0; i<n; i++) {
System.out.println("Loop de loop, flip flop.");
System.out.println("Flying in an aeroplane.");
}
}
public static void whatIf(int n) {
if(n%2==0) {
loopDeLoop(n);
}
else {
order1(n, n);
}
}
public static void whatIf2(int n) {
if(n<=10) {
loopDeLoop(n);
}
else {
order1(n, n);
}
}
public static void recursivePrint(int n) {
if(n==1) {
System.out.print(1);
}
else {
System.out.print(n+" ");
recursivePrint(n-1);
}
}
public static String StringOperation(int n) {
String tekst = "Hello";
for(int i=0; i<n; i++) {
tekst = tekst+"!";
}
return tekst+"!";
}
public static String StringOperation2(int n) {
String tekst = "Hello";
StringBuffer sb = new StringBuffer(tekst);
for(int i=0; i<n; i++) {
sb = sb.append("!");
}
return sb.toString()+"!";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment