Input Statement

need help in accepting input form keyboard

Page 1 of 1

5 Replies - 19716 Views - Last Post: 11 June 2008 - 03:11 PM Rate Topic: -----

#1 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Input Statement

Post icon  Posted 11 June 2008 - 05:42 AM

here is the code for accepting input from keyboard


   import java.io.*;  
   
	public class racker
	{
		
		private static BufferedReader stdin = 
			new BufferedReader( new InputStreamReader( System.in ) );

		
		public static void main ( String [] args ) throws IOException
		{
		  System.out.print( "Type some data for the program: " );
		  String input = stdin.readLine();

		   
			int number = Integer.parseInt( input ); 
			System.out.println( "input = " + input );

		} 

	} 


it works fine with buffered input reader but when i use datainput stream it doesnt work ne reason it gives an error
unresolved complication problem ne reason why

Is This A Good Question/Topic? 0
  • +

Replies To: Input Statement

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Input Statement

Posted 11 June 2008 - 05:58 AM

Could you post the exact error message, and the code that gives you the error?
Was This Post Helpful? 0
  • +
  • -

#3 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Input Statement

Posted 11 June 2008 - 06:06 AM

View Post1lacca, on 11 Jun, 2008 - 05:58 AM, said:

Could you post the exact error message, and the code that gives you the error?

ok here it is
ecplise put a crosss on the word readline
import java.io.*;
public class ranges {
public static void main (String args[])
{
	DataInputStream in =new DataInputStream(System.in);
	int number =0;
	try
	{
		System.out.println("Enter number");
		number =Integer.parseInt(in.readLine());
		
	}
catch(Expection e)

{
}
System.out.println("number="+number);

}
}


and it gives following error

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Expection cannot be resolved to a type

at ranges.main(ranges.java:13)
plzz help when i click on readline it says the world readline is decrypted in class datainputstream

This post has been edited by prajayshetty: 11 June 2008 - 06:07 AM

Was This Post Helpful? 0
  • +
  • -

#4 cutegrrl  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 77
  • Joined: 12-May 08

Re: Input Statement

Posted 11 June 2008 - 06:19 AM

View Postprajayshetty, on 11 Jun, 2008 - 09:06 AM, said:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Expection cannot be resolved to a type

at ranges.main(ranges.java:13)
plzz help when i click on readline it says the world readline is decrypted in class datainputstream


You wrote "Expection" it should be "Exception". Fix that and your code will compile.

The line through readLine() method (DataInputStream class) means that the code is deprecated. In other words, it signifies code which programmers are discouraged from using, typically because it is dangerous, or because a better (or newer) alternative exists.

If you want to get console input from the user use either of the following:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();

// OR

Scanner in = new Scanner(System.in);
String input = in.nextLine();


This post has been edited by cutegrrl: 11 June 2008 - 06:33 AM

Was This Post Helpful? 0
  • +
  • -

#5 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Input Statement

Posted 11 June 2008 - 08:48 AM

View Postcutegrrl, on 11 Jun, 2008 - 06:19 AM, said:

View Postprajayshetty, on 11 Jun, 2008 - 09:06 AM, said:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Expection cannot be resolved to a type

at ranges.main(ranges.java:13)
plzz help when i click on readline it says the world readline is decrypted in class datainputstream


You wrote "Expection" it should be "Exception". Fix that and your code will compile.

The line through readLine() method (DataInputStream class) means that the code is deprecated. In other words, it signifies code which programmers are discouraged from using, typically because it is dangerous, or because a better (or newer) alternative exists.

If you want to get console input from the user use either of the following:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();

// OR

Scanner in = new Scanner(System.in);
String input = in.nextLine();


well by correcting the name of exception it doesnt compiled eclipse gived same error

but can u tell me if i use scanner it dont have any conflict with any other functions of java
here is the code
import java.util.*;
public class dddd {
public static void main (String args[])
{
	 Scanner in = new Scanner(System.in);  
	  
	int number =0;
	try
	{
		System.out.println("Enter number");
		String input = in.nextLine(); 
	   number= Integer.parseInt(input);
		
		
	}
catch (Exception e){}



System.out.println("number="+number);

}
}


plzz tell
thanks for the help hope so u guys continue to provide us help as i learn java and other languages
;)

This post has been edited by prajayshetty: 11 June 2008 - 08:58 AM

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Input Statement

Posted 11 June 2008 - 03:11 PM

Cut & Pasted your last code on my Eclipse
Works perfectly


Enter number
123
number=123

This post has been edited by pbl: 11 June 2008 - 03:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1