java应用程序实例 1

时间:2025-04-06

本篇主要列举了几个常见的简单java应用程序实例。

public class TestWhile {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum=0;
int i=1;
while(i<=100)
{
sum+=i;
i++;
}
System.out.println("sum="+sum);
}

}




public class HellWord {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("liqingzhong");
System.out.print("zhangjunxiong");

}

}



public class NumberOper {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=30;
int b=40;
int r1,r2,r3,r4,r5,r6,r7,r8,r9;
//the results
r1=a+b;
r2=a*b;
r3=a/b;
r4=a%b;
r5=++a;
r6=--a;
r7=a++;
r8=a--;
r9=++b;
System.out.println("a="+a +"\nb=" +b); //output a,b result
System.out.println("a+b=" +r1);
System.out.println("a*b=" +r2);
System.out.println("a/b="+r3);
System.out.println("a%b=" +r4);
System.out.println("r5=" +r5);
System.out.println("--a=" +r6);
System.out.println("a++=" +r7);
System.out.println("a--=" +r8);
System.out.println("++b=" +r9);

}

}





public class SetVariable {

/**
* @param args
*/
//全局变量
static double pi= 3.1; //常量
static short sl=125;
static int il;
static long ll;
static char chl;
static float fl;
static double dl;
static boolean bl;


public static void main(String[] args) {
// TODO Auto-generated method stub
//local variable
short s2=35;
int i2 = -32;
long l2= 34555l;
char ch2 ='A';
float f2= 897.89F;
double d2 = 34.345;
boolean b2=false;
System.out.println("pi=" + pi);
System.out.println("*****LOCAL VARIABLE*****");
System.out.println("short s2=" +s2);
System.out.println("INT i2=" +i2);
System.out.println("long l2=" + l2);
System.out.println("CHAR ch2=" +ch2);
System.out.println("FLOAT f2=" +f2);
System.out.println("DOUBLE d2=" + d2);
System.out.println("boolean b2=" +b2);
//change();
System.out.println("*******globle variable********");
System.out.println("short sl=" + sl);
System.out.println("int il=" +il);
System.out.println("long ll="+ll);
System.out.println("char chl="+chl);
System.out.println("float fl="+fl);
System.out.println("double dl="+dl);
System.out.println("boolean bl="+bl);
System.out.println(" ok");
}
public static void change()
{
sl=125;
il=88;
ll=9876543l;
chl='B';
fl=3.2590f;
dl=-1.04e-5;
bl=true;
}
}






public class TestBit {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=36;
int b=2;
int r1,r2;
r1=a>>b;
r2=a<<b;
System.out.println("a="+a+"\nb="+b);
System.out.println("a>>b="+r1);
System.out.println("a<<b="+r2);
}

}



public class
TestFor {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum=0;
for(int i=1;i<

本篇主要列举了几个常见的简单java应用程序实例。

=100;i++)
{
sum+=i;
}
System.out.println("sum="+sum);
}

}



public class TestIf {

/**
* @param args
*/
static int x;
public static void change(){
x=5;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
x=12;
if(x>10)
{
System.out.println("x="+x+" the result of x is right");
}else
{
System.out.println("x=10"+"the result of x is wrong");
}
change();
System.out.println("the result of x that have been changed");
if(x>10){
System.out.println("x="+x+"the result of x is right");
}else
System.out.println("the result is wrong");
}

}




public class TestLogic {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean a=true;
boolean b=false;
boolean r1,r2,r3,r4,r5,r6;
r1=!a;
r2=a&&b;
r3=a||b;
r4=a&b;
r5=a|b;
r6=a^b;
System.out.println("a="+a+"\nb="+b);
System.out.println("!a="+r1);
System.out.println("a&&b=" +r2);
System.out.println("a||b=" +r3);
System.out.println("a&b=" +r4);
System.out.println("a|b="+r5);
System.out.println("a^b="+r6);
}

}




public class TestRelation {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=30;
int b=40;
boolean r1,r2,r3,r4,r5,r6;
r1=a==b;
r2=a!=b;
r3=a>b;
r4=a<b;
r5=a< …… 此处隐藏:2472字,全部文档内容请下载后查看。喜欢就下载吧 ……

java应用程序实例 1.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219