class sorts
{ public static void main(String args[]){
int arrays[]={5,4,3,8,9,7,6,2,10,1};
int i,t=0;
for(i=0;i<arrays.length();i++)
{
for(j=0;j>i;j++){
if (arrays[i]>arrays[j])
{ t=arrays[i];
arrays[i]=arrays[j];
arrays[j]=t; }
else continue;}
System.out.println(arrays[i]);}
}
}
输出结果为:
3.public class a{
public static void main(String[] args){
int m1 , m2 ;
int[][] a ;
m1=2;
m2=3;
a=new int[m1][m2];
for(int i=0 ; i<2 ; i++)
for(int j=0 ; j<3 ; j++)
a[i][j] = i*j ;
for(int i=0 ; i<a.length ; i++) {
for(int j=0 ; j<a[i].length ; j++)
System.out.print(a[i][j]+" ");
System.out.println("");
}
}
}
程序输出结果为:5. public class b{
public static void main(String[] args){
MyDate birth1,birth2 ;
birth1 = new MyDate();
birth1.day = 28 ;
birth1.month = 12;
birth1.year = 70 ;
birth1.ps();
birth2.day = 30 ;
birth2.ps();
}
}
class MyDate {
int day ;
int month ;
int year ;
void ps() {
String s1,s2 ;
s1="abc";s2="abc";
if (s1==s2) System.out.println("-----1------");
s1=new String("abc");
s2=new String("abc");
if (s1==s2) System.out.println("-----2------");
if(s1.equals(s2)) System.out.println("-----3-----"); s2=s1;
s1=s1+"def";
System.out.println("s1=" +s1 + " "+ "s2="+s2);
if(s1==s2) System.out.println("s1=s2");
}
}
程序的结果为:6. public class E04_DataOnly2 {
int i;
float f;
boolean b;
public static void main(String[] args) {
E04_DataOnly2 d = new E04_DataOnly2();
d.i = 47;
System.out.println("d.i = " + d.i);
d.f = 1.1f;
System.out.println("d.f = " + d.f);
d.b = false;
System.out.println("d.b = " + d.b);
}
}
程序的结果为:
~
7. public class E01_Precedence {
static int a,
x = 40,
y = 60,
z = 10;
public static void main(String[] args) {
a = x + y - 2/2 + z;
System.out.println(a);
a = x + (y - 2)/(2 + z);
System.out.println(a);
}
}
程序的结果为:8.~ import java.util.*;public class E09_FindPrimes {
public static void main(String[] args) {
int max = 100;
// Get the max value from the command line,
// if the argument has been provided:
if(args.length != 0)
max = Integer.parseInt(args[0]);
for(int i = 1; i < max; i++) {
boolean prime = true;
for(int j = 2; j < i; j++)
if(i % j == 0) prime = false;
if(prime)
System.out.println(i);
}} }
程序的结果为:
{ public static void main(String args[]){
int arrays[]={5,4,3,8,9,7,6,2,10,1};
int i,t=0;
for(i=0;i<arrays.length();i++)
{
for(j=0;j>i;j++){
if (arrays[i]>arrays[j])
{ t=arrays[i];
arrays[i]=arrays[j];
arrays[j]=t; }
else continue;}
System.out.println(arrays[i]);}
}
}
输出结果为:
3.public class a{
public static void main(String[] args){
int m1 , m2 ;
int[][] a ;
m1=2;
m2=3;
a=new int[m1][m2];
for(int i=0 ; i<2 ; i++)
for(int j=0 ; j<3 ; j++)
a[i][j] = i*j ;
for(int i=0 ; i<a.length ; i++) {
for(int j=0 ; j<a[i].length ; j++)
System.out.print(a[i][j]+" ");
System.out.println("");
}
}
}
程序输出结果为:5. public class b{
public static void main(String[] args){
MyDate birth1,birth2 ;
birth1 = new MyDate();
birth1.day = 28 ;
birth1.month = 12;
birth1.year = 70 ;
birth1.ps();
birth2.day = 30 ;
birth2.ps();
}
}
class MyDate {
int day ;
int month ;
int year ;
void ps() {
String s1,s2 ;
s1="abc";s2="abc";
if (s1==s2) System.out.println("-----1------");
s1=new String("abc");
s2=new String("abc");
if (s1==s2) System.out.println("-----2------");
if(s1.equals(s2)) System.out.println("-----3-----"); s2=s1;
s1=s1+"def";
System.out.println("s1=" +s1 + " "+ "s2="+s2);
if(s1==s2) System.out.println("s1=s2");
}
}
程序的结果为:6. public class E04_DataOnly2 {
int i;
float f;
boolean b;
public static void main(String[] args) {
E04_DataOnly2 d = new E04_DataOnly2();
d.i = 47;
System.out.println("d.i = " + d.i);
d.f = 1.1f;
System.out.println("d.f = " + d.f);
d.b = false;
System.out.println("d.b = " + d.b);
}
}
程序的结果为:
~
7. public class E01_Precedence {
static int a,
x = 40,
y = 60,
z = 10;
public static void main(String[] args) {
a = x + y - 2/2 + z;
System.out.println(a);
a = x + (y - 2)/(2 + z);
System.out.println(a);
}
}
程序的结果为:8.~ import java.util.*;public class E09_FindPrimes {
public static void main(String[] args) {
int max = 100;
// Get the max value from the command line,
// if the argument has been provided:
if(args.length != 0)
max = Integer.parseInt(args[0]);
for(int i = 1; i < max; i++) {
boolean prime = true;
for(int j = 2; j < i; j++)
if(i % j == 0) prime = false;
if(prime)
System.out.println(i);
}} }
程序的结果为:
-----1------
-----3-----
s1=abcdef s2=abc
-----1------
-----3-----
s1=abcdef s2=abc
d.i = 47
d.f = 1.1
d.b = false