Skip to content

Commit a15f715

Browse files
authored
Add files via upload
1 parent 42f54a7 commit a15f715

33 files changed

+1828
-0
lines changed

Dieretes.java

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package MyFirstPackage;
2+
3+
import java.util.Scanner;
4+
5+
public class Dieretes {
6+
7+
public static void main(String[] args) {
8+
// TODO Auto-generated method stub
9+
Scanner sc = new Scanner(System.in);
10+
int D;
11+
int O;
12+
int x;
13+
int counter = 0;
14+
System.out.println("Εισάγετε τιμή για τον διαιρέτη.");
15+
D = sc.nextInt();
16+
System.out.println("Εισάγετε τιμή για το όριο των διαιρετέων.");
17+
O = sc.nextInt();
18+
19+
for(int i = D; i <= O; i++ ){
20+
x = i % D;
21+
if(x == 0) {
22+
System.out.print(i +" ");
23+
counter += 1;
24+
25+
}
26+
}
27+
if(counter == 0) {
28+
System.out.println("Δεν υπάρχουν διαιρέτες.");
29+
}
30+
sc.close();
31+
}
32+
33+
}

E1.java

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* 1. Write a Java program to print 'Hello' on screen and then print your name on a separate line.
3+
Expected Output :
4+
Hello
5+
Alexandra Abramov
6+
*/
7+
8+
package w3resourceExcersises;
9+
10+
import java.util.Scanner;
11+
12+
public class E1 {
13+
14+
public static void main(String[] args) {
15+
16+
String firstName; // Declare string variable for first name.
17+
String lastName; // Declare string variable for last name
18+
Scanner sc = new Scanner(System.in); // creates scanner to receive input of first and last name.
19+
20+
System.out.println("Please, enter your first name..."); // Asks for input of first name.
21+
firstName = sc.nextLine(); // Saves first name to firstName string using scanner(sc) for later use.
22+
23+
System.out.println("Please, enter your last name..."); //Asks for input of last name.
24+
lastName = sc.nextLine(); // Saves last name to lastName string using scanner(sc) for later use.
25+
26+
System.out.println("Hello"); // Prints Hello
27+
System.out.println(firstName + " " + lastName); // Prints: firstname lastname.
28+
29+
sc.close(); // Closes Scanner (sc) to prevent resource leak.
30+
31+
}
32+
33+
}

E11.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* 11. Write a Java program to print the area and perimeter of a circle.
3+
Test Data:
4+
Radius = 7.5
5+
Expected Output
6+
Perimeter is = 47.12388980384689
7+
Area is = 176.71458676442586
8+
*/
9+
package w3resourceExcersises;
10+
11+
import java.util.Scanner;
12+
13+
public class E11 {
14+
15+
public static void main(String[] args) {
16+
// TODO Auto-generated method stub
17+
18+
Scanner sc = new Scanner(System.in);
19+
20+
System.out.println("Enter a circle radius (in cm) to calculate it's perimeter and area..");
21+
double radius = sc.nextDouble();
22+
23+
double perimeter = ( 2 * Math.PI * radius);
24+
double area = ( Math.PI * ( radius * radius) );
25+
26+
System.out.println("The circle with a radius of " + radius + "cm has a perimeter of " + perimeter + "cm and an area of " + area + "cm.");
27+
28+
sc.close();
29+
}
30+
31+
}

E12.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Write a Java program that takes three numbers as input to calculate and print the average of the numbers.
3+
*/
4+
package w3resourceExcersises;
5+
6+
import java.util.Scanner;
7+
8+
public class E12 {
9+
10+
public static void main(String[] args) {
11+
// TODO Auto-generated method stub
12+
13+
Scanner sc = new Scanner(System.in);
14+
15+
System.out.println("Enter 3 numbers to calculate their average..");
16+
double numA = sc.nextDouble();
17+
double numB = sc.nextDouble();
18+
double numC = sc.nextDouble();
19+
20+
double sum = ( numA + numB + numC ) ;
21+
22+
double avg = ( sum / 3 );
23+
24+
System.out.println("The average of the 3 numbers entered is: " + avg + " .");
25+
26+
sc.close();
27+
28+
}
29+
30+
}

E12pro.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Original: Write a Java program that takes three numbers as input to calculate and print the average of the numbers.
3+
*
4+
* Mine (pro): Write a Java program that takes an unknown amount of numbers as input to calculate and print their average.
5+
*/
6+
package w3resourceExcersises;
7+
8+
import java.util.Scanner;
9+
10+
public class E12pro {
11+
12+
public static void main(String[] args) {
13+
// TODO Auto-generated method stub
14+
15+
Scanner sc = new Scanner(System.in);
16+
17+
System.out.println("Start inputing numbers to calculate their average. Input 0 to terminate the input stream and get the output.");
18+
double numX = sc.nextDouble();
19+
double sum = numX;
20+
int i = 0;
21+
22+
while (numX != 0) {
23+
System.out.println("Insert next number...");
24+
numX = sc.nextDouble();
25+
sum = sum + numX;
26+
i++;
27+
};
28+
29+
double avg = (sum / i);
30+
System.out.println("The average of the inputed numbers( which were " + i + " in total ) is: " + avg +" .");
31+
32+
sc.close();
33+
}
34+
35+
}

E13.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Something's wrong, I can feel it... (delete line 41 to get rid of error once excersise is solved properly)
4+
*
5+
*
6+
* Write a Java program to print the area and perimeter of a rectangle.
7+
Test Data:
8+
Width = 5.5 Height = 8.5
9+
10+
Expected Output
11+
Area is 5.6 * 8.5 = 47.60
12+
Perimeter is 2 * (5.6 + 8.5) = 28.20
13+
*/
14+
package w3resourceExcersises;
15+
16+
import java.util.Scanner;
17+
18+
public class E13 {
19+
20+
public static void main(String[] args) {
21+
// TODO Auto-generated method stub
22+
23+
Scanner sc = new Scanner(System.in);
24+
25+
System.out.println("Enter the width of the rectangle of which you wish to calculate the area and perimeter..");
26+
final double width = sc.nextDouble();
27+
28+
System.out.println("Enter the height of the rectangle of which you wish to calculate the area and perimeter..");
29+
final double height = sc.nextDouble();
30+
31+
double area = ( width * height ) ;
32+
double perimeter = 2 * ( width + height );
33+
34+
System.out.println("The rectangle's area is: " + width + " * " + height + " = " + area + " .");
35+
System.out.println("The rectangle's perimeter is: 2 * ( " + width + " + " + height + " ) = " + perimeter + " .");
36+
37+
sc.close();
38+
39+
}
40+
41+
blah
42+
}

E14.java

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* 14. Write a Java program to print an American flag on the screen.
3+
Expected Output
4+
5+
* * * * * * ==================================
6+
* * * * * ==================================
7+
* * * * * * ==================================
8+
* * * * * ==================================
9+
* * * * * * ==================================
10+
* * * * * ==================================
11+
* * * * * * ==================================
12+
* * * * * ==================================
13+
* * * * * * ==================================
14+
==============================================
15+
==============================================
16+
==============================================
17+
==============================================
18+
==============================================
19+
==============================================
20+
21+
*/
22+
package w3resourceExcersises;
23+
24+
public class E14 {
25+
26+
public static void main(String[] args) {
27+
// TODO Auto-generated method stub
28+
29+
byte i = 0;
30+
31+
while (i <= 11) {
32+
if (i < 4) {
33+
System.out.println("* * * * * * ==================================");
34+
System.out.println(" * * * * * ==================================");
35+
i++;
36+
}
37+
else if (i == 4) {
38+
System.out.println("* * * * * * ==================================");
39+
i++;
40+
}
41+
else if (i < 11) {
42+
System.out.println("==============================================");
43+
i++;
44+
};
45+
}
46+
47+
48+
}
49+
50+
}

E15.java

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* 15. Write a program to swap two variables.
3+
*/
4+
package w3resourceExcersises;
5+
6+
import java.util.Scanner;
7+
8+
public class E15 {
9+
10+
public static void main(String[] args) {
11+
// TODO Auto-generated method stub
12+
13+
Scanner sc = new Scanner(System.in);
14+
15+
System.out.println("Insert the value of the 1st variable...");
16+
int varA = sc.nextInt();
17+
18+
System.out.println("Insert the value of the second variable...");
19+
int varB = sc.nextInt();
20+
21+
int temp = varA;
22+
varA = varB;
23+
varB = temp;
24+
25+
System.out.println("varA: " + varA + " ! . varB: " + varB + " !");
26+
27+
sc.close();
28+
}
29+
30+
}

E16.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* 16. Write a Java program to print a face.
3+
Expected Output
4+
5+
+"""""+
6+
[| o o |]
7+
| ^ |
8+
| '-' |
9+
+-----+
10+
11+
*/
12+
13+
14+
package w3resourceExcersises;
15+
16+
public class E16 {
17+
18+
public static void main(String[] args) {
19+
// TODO Auto-generated method stub
20+
21+
System.out.println(" +\"\"\"\"\"+ ");
22+
System.out.println("[| o o |]");
23+
System.out.println(" | ^ | ");
24+
System.out.println(" | '-' | ");
25+
System.out.println(" +-----+");
26+
27+
}
28+
29+
}

0 commit comments

Comments
 (0)