习题: 说明程序的运行结果或实现功能
1. class StringTest1 {
public static void main(String[] args)
{
String s1="hello";
String s2=new String("hello");
if((s2)){
("相等");
}else{
("不相等");
}
}
}
2
public class Sum
{ public static void main( String args[ ])
{ double sum = ;
for ( int i = 1 ; i <= 100 ; i + + )
sum += /(double) i ;
( "sum="+sum );
}
}
3. public class TestArray
{
public static void main(String args[ ]){
int i , j ;
int a[ ] = { 5,9,6,8,7};
for ( i = 0 ; i < -1; i ++ ) {
int k = i;
for ( j = i ; j < ; j++ )
if ( a[j]<a[k] ) k = j;
int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 ; i<; i++ )
(a[i]+" ");
( );
}
}
4. import .*;
public class TestFile
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader());
BufferedWriter bw = new BufferedWriter(new FileWriter(“"));
String s;
while (true)
{
("请输入一个字符串: ");
();
s=();
if (()==0) break;
(s);
();
}
();
}
}
5. class Exp1
{
public static void main(String[] args)
{
String s,s1="";
char c;
s=args[0];
for (int i=0;i<();i++)
{
c=(i);
if(c>='a' && c<='z'){
s1=s1+(c);
}else{
s1=s1+(c);
}
}
(s1);
}
}
若在dos命令行输入:java Exp1 abcDEF,则输出为。
6. import .*;
public class VecApp {
public static void main(String[] args) {
Vector v = new Vector();
for(int i = 0; i <2; i++)
("v"+i);
(new Integer(1),0);
Enumeration e = ();
while(())
(()+" ");
();
("v1" );
for(int i = 0; i < () ; i++)
((i) +" ");
();
}
}
7. class Int
java题库 来自淘豆网m.daumloan.com转载请标明出处.