Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Methods/src/Circle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import java.util.Scanner;

public class Circle {
//todo: add some methods to compute a circle's diameter, circumference and area.
//print some outputs to confirm you methods are working right.
public static double diameter(double r) {
double d = 2 * r;
return d;
}

public static double circ(double r) {
double pi = Math.PI ;
double c = 2 * pi * r ;
return c ;
}

public static double area(double r) {
double pi = Math.PI ;
double a = pi * r * r ;
return a ;
}

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
System.out.println("Radius: ");
Double r = scan.nextDouble();

System.out.println(diameter(r));
System.out.println(circ(r));
System.out.println(area(r));
}
}
21 changes: 21 additions & 0 deletions Methods/src/Prime.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@

public class Prime {

public static boolean prime(int n) {

if (n <= 1) {
return false;
} else if (n <= 3 ) {
return true;
} else if (n % 2 == 0 || n % 3 == 0) {
return false;
} else {
for (int i = 5; i * i <= n; i = i + 6 ) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
return true;
}
} return true;
}

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
int n = scan.nextInt();

System.out.println("The number " + n + " is prime: " + prime(n));
//todo: write a method which tells you if a given number is a prime or not

}
Expand Down
9 changes: 9 additions & 0 deletions Structures/src/AssignGrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ public class AssignGrade {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Score: ");
int score = scan.nextInt();

double grade = ((100 - score)/50.0) * 3 + 1;

if (grade <= 4.0) {
System.out.println("Pass with grade: " + grade);
} else {
System.out.println("Fail with grade: " + grade);
}
//todo: when executing the program you will be ask to write a score.
//The program converts the score then into a grade and prints that grade (1.0, 1.3, 1.7, ...)
//Note that the student passed when the student gets a score of 50.0 points (4.0)
Expand Down
10 changes: 10 additions & 0 deletions Structures/src/EvenOdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ public class EvenOdd {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Number: ");
int number = scan.nextInt();


for (int count = 0; count < number; count ++) {
if (count % 2 != 0) {
System.out.println(count);
}
}


//todo: The program takes a number as input.
//It then goes through all integer values till reaching that value and prints all the odd ones.
Expand Down