-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNonStaticDemo.java
40 lines (39 loc) · 1.04 KB
/
NonStaticDemo.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
//Demonstration of non static method
import java.lang.*;
import java.io.*;
class NonStaticDemo
{
public static void main(String args[])
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number to reverse :- ");
int n = Integer.parseInt(br.readLine());
NonStaticDemo rev = new NonStaticDemo(); //Non static method require to be called by object reference, as it belongs to object
System.out.println("Reverse Number is :- ");
rev.reverseNo(n);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(Exception exc)
{
exc.printStackTrace();
}
}
public void reverseNo(int n)
{
while(n > 0)
{
System.out.println(n % 10)
n /= 10; //Shorthand for n = n / 10
}
}
public String reverseNo(int n)
{
String rev = " ";
rev += n % 10;
}
}