Commit 36121ccc authored by cosmina.dunca's avatar cosmina.dunca

Withoutex10

parent 9e9435a7
...@@ -2,28 +2,47 @@ public class App { ...@@ -2,28 +2,47 @@ public class App {
/* These are the exercises for the second week of java /* These are the exercises for the second week of java
Today is 14 February 2022 Today is 14 February 2022
Cosmina Dunca */ Cosmina Dunca */
public static void main(String[] args) throws Exception { public static void countDays(){
System.out.println("Hello, World!");
int daysPerWeek = 7; // Ex 1.1 int daysPerWeek = 7; // Ex 1.1
int numberOfWeeks = 6; // Ex 1.2 int numberOfWeeks = 6; // Ex 1.2
int totalDays = daysPerWeek * numberOfWeeks; // Ex 1.3 int totalDays = daysPerWeek * numberOfWeeks; // Ex 1.3
System.out.println(totalDays); System.out.println(totalDays);
boolean onHoliday = false; // Ex 1.4 }
public static void circumference(){
double approxPI = 3.14; // Ex 1.5 double approxPI = 3.14; // Ex 1.5
double circumference = 2 * 3 * approxPI; double circumf = 2 * 3 * approxPI;
System.out.println(circumf);
}
public static String inigoSpeech(int numFingers){
String greetingString = "Hello"; // Ex 1.7 String greetingString = "Hello"; // Ex 1.7
String introductionString = "My name is Inigo Montoya"; // Ex 1.8 String introductionString = "My name is Inigo Montoya"; // Ex 1.8
String reminderString = "You killed my father"; // Ex 1.9 String reminderString = "You killed my father"; // Ex 1.9
String threatString = "Prepare to die hahaha!"; // Ex 1.10 String threatString = "Prepare to die hahaha!"; // Ex 1.10
// System.out.println(greetingString + ", " + introductionString + ", " + reminderString + ", " + threatString); // Ex 1.11 if(numFingers == 6) {
return greetingString + ", " + introductionString + ", " + reminderString + ", " + threatString; // Ex 1.11
// Exercise 4
int fingersOnRightHand = 5;
if(fingersOnRightHand == 6) {
System.out.println(greetingString + ", " + introductionString + ", " + reminderString + ", " + threatString); // Ex 1.11
} else { } else {
System.out.println("I am searching for the man who killed my father."); return"I am searching for the man who killed my father.";
} }
}
public static boolean isItALeapYear(int year){
if (year % 4 == 0){
return true;
} else{
return false;
}
}
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
countDays();
circumference();
boolean onHoliday = false; // Ex 1.4
// System.out.println(greetingString + ", " + introductionString + ", " + reminderString + ", " + threatString); // Ex 1.11
// Exercise 4 is in the method
System.out.println(inigoSpeech(5));
// Exercise 5 // Exercise 5
int month = 2; int month = 2;
...@@ -111,5 +130,98 @@ public class App { ...@@ -111,5 +130,98 @@ public class App {
System.out.println("Not a valid month"); System.out.println("Not a valid month");
} }
} }
// Exercise 7
int j = 1;
while (j < 14){
switch(j){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("Decemmber");
break;
default:
System.out.println("Not a valid month");
}
j++;
}
j = 1;
do{
switch(j){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("Decemmber");
break;
default:
System.out.println("Not a valid month");
}
j++;
}while(j < 14);
System.out.println(isItALeapYear(2011));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment