how to call a function in java
public class MyClass {
static void myMethod() {
System.out.println("You have called me! My name is: myMethod!");
}
public static void main(String[] args) {
myMethod();
}
}
how to call a function in java
public class MyClass {
static void myMethod() {
System.out.println("You have called me! My name is: myMethod!");
}
public static void main(String[] args) {
myMethod();
}
}
java method
public class Main {
public static void main(String args[]) {
SayHi();
int sum = AddNums(5, 6);
System.out.println(sum);
}
public static void SayHi() { //This method has no return value
System.out.println("Hi!");
}
public static int AddNums(int a, int b) { //This method has a return value
return a + b;
}
java methods
public class MyClass {
static int myMethod(int x) {
return 5 + x;
}
public static void main(String[] args) {
System.out.println(myMethod(3));
}
}
// Returns 8
method in java
Method is a collection of statements
which returns a value upon its execution
Method have a return and the method's name may or not be same as the class
name.
Method is invoked explicitly.
Method is not provided by compiler in any case.
Methods are inherited by child classes.
calling function in java using object
import java.util.Scanner;
public class SecondstoHrMinSec
{
static void getHours() {
int p2 = seconds / 60;
}
static void getMinutes() {
int p3 = p2 % 60;
}
public static void main(String[] args)
{
// create object of scanner class.
Scanner in = new Scanner(System.in);
// enter the seconds here.
System.out.print("Enter seconds : ");
int seconds = in.nextInt();
int p1,p2,p3;
int p1 = seconds % 60;
getMinutes();
getHours();
p2 = p2 / 60;
System.out.print("HH:MM:SS - " +p2 + ":" + p3 + ":" + p1);
System.out.print("\n");
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us