This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Reading 2 integers sperated by a space Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Reading 2 integers sperated by a space" Watch "Reading 2 integers sperated by a space" New topic
Author

Reading 2 integers sperated by a space

Lina Adam
Greenhorn

Joined: Feb 01, 2006
Posts: 3
i have to program in Java.All inputs and outputs are performed through the standard I/O.My
program should do the following:
�Read two integers b and m.The numbers are separated by a single space.they will be on the same line,and no other characters will appear on that line.And 0 <= b <m = 100,000.
�Print �Induction Expander�,followed by a newline.
�Print �If you show:�,followed by a newline
�Print �that P(b)is true�,substituting the number b you read in,followed by a newline.
�Print �and that for all k >=b,if P(k)is true,then P(k+1)is true.�,substituting
in the b you read in,followed by a newline.
�Print �Then:�,followed by a newline.
Print �P(b)is true.�,substituting the number b you read in,followed by a newline.The
program should then go into a loop,where a counter k goes from b to m-1;for each value
of k,print �P(k)is true implies P(k +1)is true.�,followed by a newline.Make sure
to replace k and k +1 with the correct values.
�Before exiting,print �Therefore,P(m)is true.�,followed by a newline.The italicized
m must be replaced by the actual value of m.

Here is what i did
// i know that ihave to use buffer reader but i don't know how and i also know that i have to use the tokenizer
System.out.println("Induction Expander");

System.out.println("If you show:");
System.out.println("that P("+b+")is true");
System.out.println("Then");

for(int k=b;K<=m-1;k++)
{
System.out.println("p("+k+"implies P("+k+1+")is true");
}
System.out.println("P("m+")");
Sant
Greenhorn

Joined: Jan 28, 2006
Posts: 15
CAN U SEND WHOLE PROGRAM WITH THE HELP OF PIECE OF CODE AM AN ABLE TO EXPLAIN OK
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If you are using Java 1.5, then you should use the Scanner class instead. It provides some methods that allow you to conveniently read primitive types from a stream. If you want to stick with the old-school i/o classes, take a look at the I/O Trail from Sun's Java tutorial (see the link in my signature for the full tutorial). If you use the right I/O classes, you won't even need to use a tokenizer. You should browse through the java.io package in the API (link in signature) to see if you can find any classes and methods will help you with this task.

Layne
[ February 01, 2006: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
Guess if myLine contains the two numbers as a string then something like

String[] myNumbers=myLine.split(" ");
int b=Integer.valueOf(myNumbers[0]).intValue();
int m=Integer.valueOf(myNumbers[1]).intValue();

Should do it.
Lina Adam
Greenhorn

Joined: Feb 01, 2006
Posts: 3
Thaks alot.
Lina Adam
Greenhorn

Joined: Feb 01, 2006
Posts: 3
One more question please.

first i'll write public class n{public void main // i don't know what to write here please help!



}
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reading 2 integers sperated by a space
 
Similar Threads
assigning int types to a boolean expression
Calculating a Given Value From an Array of integer
Please help, java program terminating unexpectedly without reason
question on operators
Battleships - guys please help me out!