Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All tasks #1

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
21 changes: 12 additions & 9 deletions src/test/java/javaTraining/module1/ArrayDeclarationActivity.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package javaTraining.module1;

import java.util.Random;

public class ArrayDeclarationActivity {

public static void main(String[] args) {

// TODO #1: Declare array of integers and Strings (without initializiation)

int[] mas1;
String[] mas2;
// END TODO #1

// TODO #2: Initialize/assign previously declared arrays with size of 10
mas1 =new int[10];
mas2 =new String[10];

// END TODO #2


// TODO #3: assign any String for 1st array element

mas2[1] = "eeeee";
System.out.println(mas2[1]);
// END TODO #3

// TODO #4: declare, initiliaze and assign 5 elements to an array in another way in one line (with curly braces)
// both - String and integer arrays
for(int i=1 ; i<=5;i++){mas1[i]= new Random().nextInt(10);
System.out.println(mas1[i]);}

// END TODO #4


// TODO #5: access 3rd element from integer array and output it

System.out.println(mas1[3]);
// END TODO #5


// TODO #6: access 1st element from String array

System.out.println(mas2[1]);
// END TODO #6
}
}
14 changes: 10 additions & 4 deletions src/test/java/javaTraining/module1/CastingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ public static void main(String arg[]) {
int
double
*/

byte buy = 23;
short sh = 100;
int in = 5;
double dub = 2.0;
// END TODO #1


// TODO #2: Write a code which will show example of Implicit Casting for previously declared variables
in=in*5;
System.out.println(in);

// END TODO #2


// TODO #2: Write a code which will show example of Explicit Casting for previously declared variables

// END TODO #2
// TODO #3: Write a code which will show example of Explicit Casting for previously declared variables
dub = dub + 5;
System.out.println(dub);
// END TODO #3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@


public class CommandLineParametersActivity {

public static void main(String[] args) {
int a= 5;
System.out.println(a);
// TODO - output first parameter from comand line
}
}
18 changes: 18 additions & 0 deletions src/test/java/javaTraining/module1/DataTypesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,29 @@ public static void main(String[] args) {
boolean
*/

byte v1 = 1;
short v2 = 2;
int v3 = 3;
long v4 = 4;
float v5 = 5;
double v6 = 6.0;
char v7 = 'E';
boolean v8 = true;

// END TODO #1


// TODO #2: initialize previously declared variables with some values

v1 = 2;
v2 = 3;
v3 = 4;
v4 = 5;
v5 = 6;
v6 = 7.0;
v7 = 'A';
v8 = false;

// END TODO #2
}

Expand Down
48 changes: 48 additions & 0 deletions src/test/java/javaTraining/module1/DecisionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ public static void main(String[] args) {
* using IF statement
* which will output "The value of theNumber is <random number>"
*/
if(theNumber == 0){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 1){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 2){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 3){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 4){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 5){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 6){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 7){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 8){
System.out.println("The value of theNumber is "+ theNumber);
}else
if(theNumber == 9){
System.out.println("The value of theNumber is "+ theNumber);
}

// END TODO #1

Expand All @@ -24,6 +54,24 @@ public static void main(String[] args) {
* which will output "The value of theNumber is <random number>"
* Print "The number is not a valid choice" if theNumber value is not in the range of 0...9
*/
int ran=10;
switch (ran) {
case 0: System.out.println("The value of theNumber is "+ theNumber);
case 1: System.out.println("The value of theNumber is "+ theNumber);
case 2: System.out.println("The value of theNumber is "+ theNumber);
case 3: System.out.println("The value of theNumber is "+ theNumber);
case 4: System.out.println("The value of theNumber is "+ theNumber);
case 5: System.out.println("The value of theNumber is "+ theNumber);
case 6: System.out.println("The value of theNumber is "+ theNumber);
case 7: System.out.println("The value of theNumber is "+ theNumber);
case 8: System.out.println("The value of theNumber is "+ theNumber);
case 9: System.out.println("The value of theNumber is "+ theNumber);
default:
System.out.println("The number is not a valid choice");
break;

}


// END TODO #2

Expand Down
10 changes: 9 additions & 1 deletion src/test/java/javaTraining/module1/ForLoopActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public class ForLoopActivity {
public static void main(String[] args) {

// TODO #1: print numbers from 1 to 10 by using FOR loop
for (int i=1 ;i<=10; i++){
System.out.println(i);
}

// END TODO #1

Expand All @@ -17,7 +20,12 @@ public static void main(String[] args) {
* * * * * * * * * *
Hint - use nested FOR loop
*/

for (int i = 1; i<=5; i++){
for (int a=1 ;a<=10; a++){
System.out.print(a+" ");
}
System.out.println();
}
// END TODO #2
}
}
21 changes: 18 additions & 3 deletions src/test/java/javaTraining/module1/MethodActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,46 @@ public class MethodActivity {

// TODO #1: write a method which will output "Hello!"

public static void getPub(){
System.out.println("Hello!");
}

// END TODO #1

// TODO #2: write a static method which will output "Hello!"
public static void pub2(){
System.out.println("Hello!");
}

// END TODO #2

// TODO #3: Write method which returns a sum of 2 numbers. 2 numbers should be passed as parameters.

public int getSumm(int a, int b){
int sum;
sum = a+b;
return sum;
}
// END TODO #3


public static void main(String arg[]){

// TODO #4: Invoke a method from TODO #1. HINT - main() method is a STATIC method

MethodActivity met = new MethodActivity();
met.getPub();
// END TODO #4


// TODO #5: Invoke a method from TODO #2. (Try to invoke it 2 ways possible)

pub2();
// END TODO #5


// TODO #6: Invoke a method from 3rd 'TODO'. Assign return value of this method to a variable and output it

int a =2;
int b =5;
System.out.println(met.getSumm(a ,b));
// END TODO #6
}
}
25 changes: 23 additions & 2 deletions src/test/java/javaTraining/module1/OperatorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,37 @@ public static void main(String[] args) {

//TODO - assign the sum of x and y to z variable

z = x+y;
System.out.println("X and Y summ "+z);

//TODO - write z=z+1 in a shorter way (2 ways possible)
z++;
System.out.println(z);
++z;
System.out.println(z);

//TODO - Increment x by 1 and the assign it to z

z=x++;
System.out.println(z);
//TODO - Assign x variable to z variable and the increment x by 1. NOTE - should be done as one expression

z=x++;
System.out.println(z);
//TODO - show example of RELATIONAL operator

if(z==2){
System.out.println("ir vienads");
}else{
System.out.println("nav vienads");
}

//TODO - show example of LOGICAL operator

if(z ==1 && x==2){
System.out.println("nav vienadi");
}

//TODO - show example of ()? ():() operator
System.out.println((z>x) ? z:x);

}
}
22 changes: 22 additions & 0 deletions src/test/java/javaTraining/module1/VariableActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ public class VariableActivity {
3. Local variables with primitive and object variables
*/


//Instance
public int a1=1;


//Class
public static int a2=2;

//Local
public void getVariable3(int a3){
System.out.println(a3);
}
// END TODO #1


// TODO #2: initialize previously declared instance variable with some value in one method and output it in other method
// Is it possible to have access to local variable from multiple methods?

public static void main(String[] args){
VariableActivity va = new VariableActivity();
System.out.println(va.a1);

System.out.println(a2);

va.getVariable3(3);
}


// END TODO #2
}
6 changes: 5 additions & 1 deletion src/test/java/javaTraining/module1/WhileLoopActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ public class WhileLoopActivity {
public static void main(String[] args) {

// TODO #1: print numbers from 1 to 10 by using WHILE loop

int i = 1;
while(i<=10 ){
System.out.println(i);
i++;
}
// END TODO #1
}
}
Loading