How to make functions in java:
class Fuction
{
private int len,hei;
public void setData( int i , int h)
{
len=i;
hei=h;
}
public void showData()
{
System.out.println("Length is:" +len);
System.out.println("Height is:" +hei);
System.out.println("Total length multiple height is:" +(len*hei));
}
public static void main(String args[])
{
Fuction u= new Fuction();
u.setData(13,6);
u.showData();
}
}
How to user input value:
import java.util.*;
public class User
{
public static void main(String args[])
{
Scanner u = new Scanner(System.in);
System.out.print("Enter a number:");
int a=u.nextInt();
int s=a+10;
System.out.println("You entered number:" +s);
}
}
How to print current date/time:
import java.util.*;
class DateTime
{
public static void main(String args[])
{
Calendar obj = new GregorianCalendar();
int h , m , s;
h = obj.get(Calendar.HOUR);
m = obj.get(Calendar.MINUTE);
s = obj.get(Calendar.SECOND);
System.out.println(h+" : " +m+ " : "+s);
}
}
How to print table:
import java.util.*;
public class User
{
public static void main(String args[])
{
Scanner u = new Scanner(System.in);
System.out.print("Enter a number:");
int a=u.nextInt();
int s=a+10;
System.out.println("You entered number:" +s);
}
}
0 Comments