File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scanner Example from K&B. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scanner Example from K&B." Watch "Scanner Example from K&B." New topic

Scanner Example from K&B.

aruna dabas

Joined: Dec 16, 2008
Posts: 27
dear Friends Please Explain me this code.

import java.util.Scanner;
public class ScanNext{
public static void main(String args[]){
boolean b2,b;
int i;
String s,hits=" ";
Scanner s1=new Scanner(args[0]);
Scanner s2=new Scanner(args[0]);
hits += "s";
}else if(s2.hasNextBoolean()){
hits +="b";
}else{;hits +="s2";}
System.out.println("hits" +hits);

if this program is invoked with
% java ScanNext "1 true 34 hi"

it produces
hits ssssibis2

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I have modified the code a bit. Now you must be able to figure it out yourself.

Good luck,
Wouter Oet

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I forgot:

Please note that there is a difference between

java ScanNext "1 true 34 hi"
java ScanNext 1 true 34 hi

Good luck,
Wouter Oet
kshitij dogra
Ranch Hand

Joined: Dec 28, 2008
Posts: 39
well thats a bit simple aruna

In the first while loop the default delemiter is 'space'. So as comes new literals may they be boolean, int etc. 's' is being concatenated

In the second while; again the defalut delimeter is space, but here you are being precise , as you are distinguishing between

SCJP 5.0 - 100%
I agree. Here's the link:
subject: Scanner Example from K&B.
jQuery in Action, 3rd edition