-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Java.java
More file actions
85 lines (62 loc) · 1.76 KB
/
Test_Java.java
File metadata and controls
85 lines (62 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.May2023;
import java.util.Arrays;
import java.util.Scanner;
public class Test_Java
{
int goal = 1;
public void testChar()
{
//Default value for char is space
char ch[] = new char[3];
System.out.println(Arrays.toString(ch));
}
//test properties of Scanner class
public void test_Scanner()
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a value");
System.out.println(scan.next());
}
public void test_tryWithResources()
{
try(Scanner scan = new Scanner(System.in))
{
System.out.println("Enter a val");
System.out.println(scan.next());
}
}
public void test_ReturnKeyword()
{
String str = "val";
if(str.equals("val"))
{
System.out.println("values are matching");
//the method is exited when JVM encounters the below Return statement
return;
}
else
System.out.println("no");
//The below statement does NOT get printed because program exits due to return statement in the "if" condition
System.out.println("out of loop");
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "Print values of variables: "+goal;
}
public static void main(String[] args)
{
Test_Java java = new Test_Java();
//java.testChar();
//java.test_Scanner();
java.test_tryWithResources();
Test_Java goaler1 = new Test_Java();
Test_Java goaler2 = new Test_Java();
System.out.println("goaler1.goal:- "+goaler1.goal); //prints- 1
goaler1.goal +=1;
System.out.println("goaler1.goal +=1 :- "+goaler1.goal); //prints- 2
System.out.println("goaler2.goal:- "+goaler2.goal); //prints- 1
System.out.println(java);
java.test_ReturnKeyword();
}
}