Read Answer(1) | 10,005 Views |
why main method have all needed keyword like public void main?
if i write private in contrast of public then what happen and why?
Read Answers(3) | 6,315 Views |
1-Write a function named isSquare that returns 1 if its integer argumentis a square of some integer, otherwise it returns 0. Yourfunction must not use any function or method (e.g. sqrt)that comes with a runtime library or class library!
The signature of the function is
int isSquare(int n)
Examples:
| if n is | return | reason |
| 4 | 1 | because 4 = 2*2 |
| 25 | 1 | because 25 = 5*5/td> |
| -4 | 0 | because there is no integer that when squared equals -4. (note, -2 squared is 4) |
| 8 | 0 | because the square root of 8 is not an integer. |
| 0 | 1 | because 0 = 0*0 |
Post An Answer | 3,474 Views |
An array is said to be hollow if it contains 3 or more zeros in themiddle that are preceded and followed by the same number of non-zero elements.Furthermore, all the zeroes in the array must be in the middle of the array.Write a function named isHollow that accepts an integer array andreturns 1 if it is a hollow array, otherwise it returns 0.
If you are programming in Java or C#, thefunction signature is
int isHollow(int[ ] a)
If you are programming in C or C++, thefunction signature is
int isHollow(int a[ ], int len) where len is the number of elements in thearray
Examples:
| if the input array is | is hollow? | reason |
| {1,2,0,0,0,3,4} | yes | 2 non-zeros precede and follow 3 zeros in the middle |
| {1,1,1,1,0,0,0,0,0,2,1,2,18} | yes | 4 non-zeros precede and follow the 5 zeros in the middle |
| {1, 2, 0, 0, 3, 4} | no | There are only 2 zeroes in the middle; at least 3 are required |
| {1,2,0,0,0,3,4,5} | no | The number of preceding non-zeros(2) is not equal to the number of following non-zeros(3) |
| {3,8,3,0,0,0,3,3} | no | The number of preceding non-zeros(3) is not equal to the number of following non-zeros(2) |
| {1,2,0,0,0,3,4,0} | no | Not all zeros are in the middle |
| {0,1,2,0,0,0,3,4} | no | Not all zeros are in the middle |
| {0,0,0} | yes | The number of preceding non-zeros is 0 which equals the number of following non-zeros. And there are three zeros “in the middle”. |
Hint: Write three loops. The first counts thenumber of preceding non-zeros. The second counts the number of zeros in themiddle. The third counts the number of following non-zeros. Then analyze theresults.
Post An Answer | 2,861 Views |
What is the difference between java command line arguments and C command line arguments?
Read Answer(1) | 5,363 Views |
When i am working with Rmi “Hello world” program without Stub and skeleton the program has been working .
This is remote interface
import java.rmi.*;
public interface SmallInter extends Remote {
public String getMesg(String s) throws RemoteException;
}
This is my server side program
import java.rmi.*;
import java.rmi.server.*;
public class SmallServer extends UnicastRemoteObject implements SmallInter
//to convert local object into remote object
{
public SmallServer() throws RemoteException {
}
public String getMesg(String s) throws RemoteException {
String s1 = “This is a message from server after a message” + s;
return s1;
}
public static void main(String arg[]) {
try {
SmallServer ser = new SmallServer();
Naming.rebind(”small”, ser);
System.out.println(”server ready”);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is my Client side code:
import java.rmi.*;
public class SmallClient {
public static void main(String arg[]) {
try {
SmallInter remobj=(SmallInter)Naming.lookup(”rmi://”+arg[0] +”/small”);
System.out.println(remobj.getClass());
String res = remobj.getMesg(”from client”);
System.out.println(res);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
but when printing the remobj.getClass() it will retuen some “class $proxy”
How this is possible?
please give me the answer………..
Post An Answer | 2,032 Views |
How do you pass data (including JavaBeans) to a JSP from a servlet?
Read Answer(1) | 6,290 Views |
What is the difference between doPost and doGet methods?
Read Answer(1) | 5,673 Views |
How can you minimize the need for garbage collection and make memory use more effective?
Read Answers(2) | 6,824 Views |
What is the primary difference between a Vector and an ArrayList?
Read Answer(1) | 6,620 Views |