• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner Example from K&B.

 
aruna dabas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]);
while(b=s1.hasNext()){
s=s1.next();
hits += "s";
}
while(b=s2.hasNext()){
if(s2.hasNextInt()){
i=s2.nextInt();
hits+="i";
}else if(s2.hasNextBoolean()){
b2=s2.nextBoolean();
hits +="b";
}else{
s2.next();hits +="s2";}
}
System.out.println("hits" +hits);
}
}

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

it produces
hits ssssibis2

THANK YOU.
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post the same question more than once. Cross-posting causes confusion and duplication of effort as the community tries to help everyone.
CarefullyChooseOneForum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic