-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_and_methods.java
43 lines (37 loc) · 1.15 KB
/
functions_and_methods.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
import java.util.Scanner;
public class functions_and_methods {
// Functions and methods in Java
public static void print_java(){
System.out.println("Hello, Welcome to Java.");
}
public static void intro(String name2) {
System.out.println("Name: " + name2);
System.out.println("BCA");
System.out.println("T.M.B.U.");
}
// Another Example - With Arguements
public static void greeting(){
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
String name1 = sc.nextLine();
System.out.println("Hello, "+ name1);
System.out.println("Welcome to Java.");
sc.close();
}
public static void addition(){
System.out.print("Enter two numbers: ");
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = a+b;
System.out.println("Addition: " + c);
sc.close();
}
public static void main(String[] args) {
// Functions and Methods
print_java();
intro("Mohsin");
greeting();
addition();
}
}