-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScan.java
More file actions
92 lines (63 loc) · 1.58 KB
/
Scan.java
File metadata and controls
92 lines (63 loc) · 1.58 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
86
87
88
89
90
91
92
import java.util.Scanner;
import java.util.Hashset;
import java.util.set;
public class Scan {
public static void main(String[] args) {
/// ARRAY / String[] Array
String[] arr = new String[3];
arr[0] = "hi";
arr[1] = "hello world";
arr[2] = "Hello World";
int[] arr2 = {3, 4, 25, 36, 83, 3};
int var_y = arr2[3];
String var_x = arr[1];
System.out.println(var_x);
/// SCANNER user_input
Scanner sc = new Scanner(System.in); // waits for user input
String s = sc.nextLine(); //
/// if String == var: / if else if else / s.equals()
if (s.equals("hello world")) // user input must be == "hello world"
{
System.out.println("success");
} else if (s.equals("Hello World")){
System.out.println("success");
} else {
System.out.println("fail");
}
/// for i in range(len(array)):
for (int i = 0 ; i < arr2.length ; i++) {
if (arr2[i] == 36) {
System.out.println(arr2[i]);
}
}
/// for i in arr2:
int count = 0;
for (int i:arr2) {
System.out.println(i + " " + count);
count++;
}
/// iter over empty array add user input to i in array
String[] names = new String[5];
Scanner sca = new Scanner(System.in);
for (int i = 0; i < names.length; i++) {
System.out.print("input: ");
String input = sca.nextLine();
names[i] = input;
}
/// for i in var:
for (String n:names) {
System.out.println(n);
if (n.equals(names[3])) {
break;
}
}
/// SET / HASHSET
set<Integer> t = new HashSet<Integer>();
t.add(5);
t.add(345);
t.add(12);
t.sixe();
int x = t.size();
System.out.println(x);
}
}