Java Reference
In-Depth Information
if
(minimum . compareTo ( a r g s [ i ] )
>
0)
minimum=a r g s [ i ] ;
System . out . println (
"Lexicographically minimum string is:"
+minimum) ;
}
}
For example, calling the above compiled program with arguments
rock doll
dance dancing
, we get:
prompt%java ParsingArgument rock doll dance dancing
Lexicographically minimum string is:dance
5.7 Revisiting a basic program skeleton
Let us close this chapter by writing a small skeleton program that defines a
new
class and uses this class in the
main
function of the
program
class:
Program 5.12
A more evolved basic skeleton program that also defines
classes
class
Point
int
x,y;
Point(
int
xx ,
int
yy)
{
x=xx ; y=yy ;
}
}
// end of class Point
class
Skeleton
// Static class variables
static int
nbpoint=0;
static double
x;
static boolean
[] prime;
static int
f1(
int
p)
{
return
p/2;
}
static int
f2(
int
p)
{
return
2
∗
}
p;
public static void
Display(Point p)
{
System . out . println (
"("
+p . x+
","
+p . y+
")"
);
}
public static void
main( String [ ] argArray)
System . out . println ( f2 ( f1 (3) )+
" versus (!=) "
+f1 ( f2 (3) ) ) ;
Point p,q;
p=
new
Point (2 ,1) ; nbpoint++;
q=
new
Point (3 ,4) ; nbpoint++;
Display(p) ;
Display(q) ;
}}
Search WWH ::
Custom Search