Java 小程序
1.功能:I am ,We are
class Who{
public static void main(String[] args){
if(args.length<1)
System.out.println("who are u?");
if(args.length==1)
System.out.println("I am "+args[0]);
if(args.length>1)
{System.out.print("We are ");
for(int i=0;i<args.length-1;i++)
System.out.print(args[i]+",");
System.out.println(args[args.length-1]+".");}有趣的java小程序
}
}
2.功能:
class Yichang{
public static void main(String[] args){
void method(int m){
int i;
for(i=0;i<m;i++){
system.out.println(args[i]);
}
}
}
}
3.功能:
class Yichang{
public static void main(String[] args){method(5,args);}
public static void method(int m,String args[])throw Exception{
int i;
if(m>arg.length)throw new Exception ("ERROR");
for(i=0;i<m;i++){system.out.println(args[i]);
}
}
void methodCaller{
try{method(IO);
}catch (Exception e){
i=m;
}
}
}
4.功能:
class Zuixiao{
public static void main(String[] args){
int min,x,y,z;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]);
z=Integer.parseInt(args[2]);
if(x>y){
min=y;y=x;x=min;
}
if(x>z){
min=z;z=x;x=min;
}
System.out.println("最小数是"+x);
}
}
5.功能:
import java.io.*;
class Calculate1{
public static void main(String[] args){
int c;
System.out.println("ÊäÈëÒ»¸öÔËËãʽ");
try{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
BufferedReader br3=new BufferedReader(new InputStreamReader(System.in));
String adLine();
String adLine();
String adLine();
if(s2.eauals("+"))
c=Integer.parseInt(s1)+Integer.parseInt(s3);
if(s2.eauals("+"))
c=Integer.parseInt(s1)-Integer.parseInt(s3);
if(s2.eauals("+"))
c=Integer.parseInt(s1)*Integer.parseInt(s3);
if(s2.eauals("+"))
c=Integer.parseInt(s1)/Integer.parseInt(s3);
System.out.println(c);
}
catch(Exception e){
System.out.Message());
}
}
}
6.功能:
import java.io.*;
class Jiafa{
public static void main(String[] args){
try{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String a1,a2;
int b1,b2,c;
System.out.print("请输入第一个数字:");
adLine();
b1=Integer.parseInt(a1);
System.out.print("请输入第二个数字:");
adLine();
b2=Integer.parseInt(a2);
c=b1+b2;
System.out.println(c);
}
catch(Exception e){
System.out.Message());
}
}
}
7.功能:
class Sanjiao{
public static void main(String[] args){
System.out.println(Math.sin(60.0/180*Math.PI));
}
}
8.功能:
import java.io.*;
class I{
public static void main(String[] args){
System.out.print("I am ");
try{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String adLine();
System.out.println("you are "+s); }
catch(Exception e){
System.out.Message());
}
}
}
9.功能:
class Xiangjia{
public static void main(String[] args){
System.out.println(Integer.parseInt("123"+"456"+"789"));
}
}
10.功能:
class Helloworld{
puclic static void main(String[] args){
System.out.println("Hello world!");
}
}
11.功能:
class Who{
public static void main(String[] args){
System.out.println(Integer.parseInt(args[0])+Integer.parseInt(args[1]));
}
}
12.功能:
class Zuida{
public static void main(String[] args){
System.out.Zuida(6,9));}
public static int getZuida(int m,int n){
while (m!=n){
if(m>n) m=m-n;
f(m<n) n=n-m;}
return m;}}
检查java环境是否可运行:
建立新建:变量名:java_home
变量值:C:\java
双击path:变量名:path
变量值:C:\Java\bin
新建 :变量名:classpath
变量值:,;java_home%\lib;%java_home%\lib\dt.jar;%java_home%\lib\tools.jar;
运行 :cmd
路径:cd C:\java
编译 :javac 文件名.java
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论