• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading 2 integers sperated by a space

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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+")");
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CAN U SEND WHOLE PROGRAM WITH THE HELP OF PIECE OF CODE AM AN ABLE TO EXPLAIN OK
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thaks alot.
 
Lina Adam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more question please.

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



}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic