How to use simple input command ?

I am tired of trying to find an easy to understand source to implement simple INPUT command ( equivalent to cin>> and scanf() , in c++ and c as i m good in those two)when print can be System.out.println(--) , then y does read have to be so complicated ?Help me out guys
[300 byte] By [imencoded128bita] at [2007-11-27 7:57:10]
# 1
Look at the Scanner class.
floundera at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 2
Em, please , can u be more specificc ? Please - i m not so confident with Java yet, u c i cant even take input ?Someone please explain the syntax:(
imencoded128bita at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 3

http://java.sun.com/j2se/1.5.0/docs/api/

The above link is the the java API for version 5. If you are not familiar with the API, now is a good time to learn. It lists all the classes and the methods they have and have inherited. Go and read and become confident. Try to write code yourself. Yes, you will make mistakes, we all do. That is how you learn. You won't learn from copying any code that I post here.

If you are having trouble then post back here with your code (wrapped in code tags), post the exact error messages you get (if any) and provide a clear explanation of the trouble you have. Don't say "It doesn't work".

floundera at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 4

package palindrome;

import java.io.DataInputStream;

/**

*

* @author Pulkit

*/

class Main {

public static void main(String[] args) {

int num;

System.out.println("Enter a number to check if it is palindrome");

// System.in.readline(num);

DataInputStream ob = new DataInputStream(System.in);

}

}

Now the remark line is wat i tried to do, as i thought it should follow the print method ( System.out.print ) that one.

But in a book , i see its done just the other way, just below the rem line.

I just need ur help to explain me as to how that line has been put, i.e. the syntax of that line.

imencoded128bita at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 5
HEy flounder !!!!That link is superb ! A whole encyclo kinda thing !Thanks a lot :)
imencoded128bita at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 6
So you totally ignored my reply in post #1?
floundera at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 7

Can u please debug the above code for me ?

I am using net beans 5.5

It compiles without errors but when i run it using F6 button . . .it displays the message but does not wait for me to enter value . . . help ?

U can call it my first program . . . If u help me with this, i wud be able to do atleast 25-30% since i m master in c and c++ most of other syntaxes are same . .

imencoded128bita at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 8
USE A SCANNERWhen you have done that and still can't get it to work, post your updated code as well as any error messages.Paste code, highlight it, click code button. This retains formatting.
floundera at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...
# 9

OH WOWOWOWOW !!

My first program ! It worked !

THanks a lot sir, Thanks a lot.

Can u just tell me why the java.io.datainput stream method did not work ?

package palindrome;

import java.util.Scanner;

import java.io.DataInputStream;

/**

*

* @author Pulkit

*/

class Main {

public static void main(String[] args) {

int num;

System.out.println("Enter a number to check if it is palindrome");

Scanner ob = new Scanner(System.in);

num=ob.nextInt();

}

}

imencoded128bita at 2007-7-12 19:39:00 > top of Java-index,Java Essentials,Java Programming...