-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionInjava.java
88 lines (69 loc) · 2.16 KB
/
functionInjava.java
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
package com.petehouston.tutorial.java;
import java.util.Arrays;
import java.util.Scanner;
import java.lang.Math;
import java.lang.String;
import java.util.Random;
public class HelloWorld {
public static void main(String[] args) {
Random rand = new Random();
int[][] nums = new int[3][3];
for (int i=0; i< nums.length; i++){
for (int j=0; j<nums[i].length; j++) {
int randNumber = rand.nextInt(50);
int mathRand = 10 +(int) (Math.random()*40);
nums[i][j] = mathRand;
};
}
for (int j=0; j<nums.length; j++){
for (int i=0; i<nums[j].length; i++){
System.out.printf("%d ",nums[j][i]);
}
System.out.println();
}
int[][] matrix = {
{1,2,3},
{7,9,0}
};
System.out.println(Arrays.toString(matrix[0]));
String[][] strings = new String[2][3];
strings[0][1] = "Hello";
System.out.println(strings[0][1]);
hello();
welcome();
int a = 7, b = 8;
int c = sum(a,b);
System.out.println(c);
multip("Meiirzhan",1,2,5,7);
Scanner scan = new Scanner(System.in);
System.out.print("\nEnter hour = ");
int h = scan.nextInt();
String res = dateTime(h);
System.out.println(res);
}
static void hello(){
System.out.println("Hello Java");
}
static void welcome(){
System.out.println("Welcome to Java 17.0.1");
}
static int sum(int x, int y){
int z = x + y;
return z;
// System.out.printf("Sum %d + %d = %d",x,y,z);
}
static void multip(String s, int ...j){
int result = 1;
for(int i: j){
result *= i;
}
System.out.printf("\n%s , result = %d",s,result);
}
static String dateTime(int hour){
if (hour > 24 || hour<0) return "Invalid data";
else if (hour > 24 || hour < 6) return "Good night";
else if (hour >= 15) return "Good evening";
else if (hour >= 11) return "Good afternoon";
else return "Good morning";
}
}