String s=reader.nextLine(); int n=s.length();
char a[]=new char[n]; int c1=0,c2=0,c3=0,i;
for(i=0;i if(a[i]>='A' && a[i]<='Z'||a[i]>='a'&&a[i]<='z') c1++; else if(a[i]>='0' && a[i]<='9') c2++; else c3++; } System.out.println(\英文字母的个数:\ System.out.println(\数字的个数:\ System.out.println(\其它字符的个数\ } } //********************************************************** // 将用户从键盘上输入的每行数据都显示出来,直到输入字符串\程序运行结束。 import java.util.Scanner; class U20_5{ public static void main(String args[]){ Scanner reader=new Scanner(System.in); String s=reader.nextLine(); while(!s.equals(\ System.out.println(\ s=reader.nextLine(); } } } //**************************************************** //选择排序法(升序) class Sort1{ public static void main(String args[]){ int a[]={253,2,1,6,8,9,10}; int n=a.length; int i,j,t; //**** 选择排序法(降序) for(i=0;i //***********输出排序结果************** for(i=0;i } //************************************************************* //冒泡排序法(升序) class Sort2{ public static void main(String args[]){ int a[]={253,2,1,6,8,9,10}; int n=a.length; int i,j,t; //**** 冒泡排序法(升序) for(i=n-2;i>=0;i--){ for(j=0;j<=i;j++){ if(a[j]>a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t; } } } //***********输出排序结果************** for(i=0;i //**************以下是类方法、实例方法举例******************* //--------------------- 用类的实例方法,将一维数组作为形参进行排序 class Test1{ public static void main(String args[]){ int a[]={253,2,1,6,8,9,10}; S1 ob1=new S1(); ob1.sort1(a); for(int p:a) System.out.println(p); } } class S1{ void sort1(int x[]){ int i,j,t,n=x.length; for(i=n-2;i>=0;i--){ for(j=0;j<=i;j++){ if(x[j]>x[j+1]){t=x[j];x[j]=x[j+1];x[j+1]=t; } } } } } //--------------- 用类方法,将一维数组作为形参进行排序 class Test2{ public static void main(String args[]){ int a[]={253,2,1,6,8,9,10}; S1.sort1(a); for(int p:a) System.out.println(p); } } class S1{ static void sort1(int x[]){ int i,j,t,n=x.length; for(i=n-2;i>=0;i--){ for(j=0;j<=i;j++){ if(x[j]>x[j+1]){t=x[j];x[j]=x[j+1];x[j+1]=t; } } } } } //******************** 位操作 **** |、&、~、^ 、>>、>>>、<<***** 例: byte a=-12,b=8; byte c=a^b; 请手工推算一下c=?(写出推算步骤和最终计算结果) (1) 先将 a和b 转化成二进制原码 a=100001100 b=000001000 由于 a是负数必须先求补码 a补码=111110100 a补码^b=111111100 (2) 由于高位为1需再求一次补码方为结果,c=100000100 (3) 转化为十进制,结果 c= -4
相关推荐: