write a program to get input as "12+5-7" like this and print output without using standard function,,
no builtin java functions to be used to get any input like this and also for output,,,
Printable View
write a program to get input as "12+5-7" like this and print output without using standard function,,
no builtin java functions to be used to get any input like this and also for output,,,
What does "builtin functions" mean? You mean methods from classes like Scanner and System?
CJSL
we should not use methods that are present in any classes..
if system class can be used,,, then i can simple use System.out.println(); method,,,, these methods should not be used, so give any way to write without using these methods
The only thing that I can think of (and is from C++ world) is writing to stdout:
I have no idea if there's something similar in JavaCode:cout << "x=" << 3 << endl;
Luck,
CJSL
I don't think so there is such a way in Java.
To our thread starter, is this the exact question ask from you in that interview.
Hello all!
This is quite a challenge. I am just a beginner when it comes to programming. I may, however, have a solution for getting input.
Could you possibly use the FileReader and BufferedReader classes? These are not standard classes for getting input, but they can be used to get input from text files.
As far as output goes, I cannot think of anything. There might be a class in the javax.swing libraries.
I think you simply can't. Even using a BufferedReader to read input and a PrintWriter to display output is useless, because you have to attach them to System.in and System.out. So you'll eventually happen to use the same readLine() and println()... All you done was creating 2 new useless objects.
I studied this problem because it's fascinating, and now I think that there is no Sun Java specification to access the hardware directly (Yes, you should have direct access to the hardware not to use "standard" methods). If you don't want to use any println() or read() method of the standard library you'll end up using NATIVE (C++) method, and I don't think this is what you want. Even AWT uses native method to use the hardware, there's no Java interface to it.
Maybe you misunderstood the meaning of "standard function". In my opinion it simply says "Don't use the Scanner class". Keep in mind that the Java language is made up by some classes. For example, it is impossible to create a Class which doesn't inherit from Object... You must use Object, Exception, Thread, Integer and... PrintStream!
If you can't use built-in functions, how is it possible? You would have to reinvent the wheel every time because you would have to write your own version of the classes that are already built for you in the libraries.
If I am misunderstanding that and you can in fact use built-in functions (just not the standard ones), you could possibly create shapes and draw the output on the screen by moving and manipulating the shapes to make words. This would not require the use of System.
Cheers
That's why most of the people mess with this thread. :)
Eranga, I don't understand you. I silmply think that, if you can't use neither System.in or System.out, THE ONLY WAY to read input and display output si c++ code. If you downloaded the source of the Sun JDK and looked at System.java you could realize it. Althought System.in and System.out are declared to be a BufferedReader and a PrintStream, they're implemented through NATIVE code. So, if Sun used c++ to get it, how could you avoid it?
In my opinion, simply there isn't a way to "java coding" such a thing: you should use another language. That's why (imvho) j2vdk misunderstood the meaning of "standard function": without using System.in, System.out and their methods, you can't use Java code. But maybe this is a way to test its ability in mixing java and native code... (And this happen to be a lil strange...)
I think you are misunderstand here. Look at the third post of this thread.
What you think about that?Quote:
we should not use methods that are present in any classes..
For me, you cannot do this in Java. Because anyhow he has to use any standard function such as println(), print(), printf().... I don't know any way to do this without using standard functions on Java classes. Using C/C++ it's possible, but not with Java.
I don't see any problem. We totally agree. If he needs to avoid existing methods, he has to use tha java native interface. I simply wrote this in my previous posts.
In the 1st post j2vdk said:
And then, after a few posts:Quote:
write a program to get input as "12+5-7" like this and print output without using standard function
I think this two things are slightly different, because you could EITHER use non-standard ways to get that (maybe you rely on an existing project using import statement, ore use an exotic jdk class whose existence I am not aware of) OR you have to reimplement by yourself that functionality. These are 2 different things and if he needs the latter (completely new implementation) then he can only write C++ code through JNI. Java by itself is not sufficient (look at the Sun JDK source).Quote:
we should not use methods that are present in any classes
Good Bye
Then what's the non-standard way to do this in Java? I think you are talking about the native interface implementation using C/C++, right?
Yes, you guessed. There is no other way. Take a look at the source of JDK 5 System.java
It's quite difficult to read, I've not understood it very well. But I realized that, to read from the keyboard and sending output to the screen, your only chance is to use C++ code.Code:public final class System {
/* First thing---register the natives */
private static native void registerNatives();
static {
registerNatives();
}
...
public final static InputStream in = nullInputStream();
...
}
Bye
Ya ya, I know that story lol. :) We just mess up here. It's clear now.