当前位置: 首页 > news >正文

成都企业如何建网站做直播网站需要手续

成都企业如何建网站,做直播网站需要手续,越秀区手机版网站建设,php小程序商城【程序1】 题目#xff1a;古典问题#xff1a;有一对兔子#xff0c;从出生后第3个月起每个月都生一对兔子#xff0c;小兔子长到第三个月后每个月又生一对兔子#xff0c;假如兔子都不死#xff0c;问每个月的兔子对数为多少#xff1f; 程序分析#xff1a; 兔子… 【程序1】 题目古典问题有一对兔子从出生后第3个月起每个月都生一对兔子小兔子长到第三个月后每个月又生一对兔子假如兔子都不死问每个月的兔子对数为多少 程序分析 兔子的规律为数列1,1,2,3,5,8,13,21.... public class Prog1{        public static void main(String[] args){               int n 10;               System.out.println(第n个月兔子总数为fun(n));        }        private static int fun(int n){               if(n1 || n2)                  return 1;               else                  return fun(n-1)fun(n-2);        } } 【程序2】 题目判断101-200之间有多少个素数并输出所有素数。 程序分析判断素数的方法用一个数分别去除2到sqrt(这个数)如果能被整除则表明此数不是素数反之是素数。 public class Prog2{     public static void main(String[] args){         int m 1;         int n 1000;         int count 0;         //统计素数个数         for(int im;in;i){             if(isPrime(i)){                 count;                 System.out.print(i );                 if(count%100){                     System.out.println();                 }             }         }         System.out.println();         System.out.println(在m和n之间共有count个素数);     }     //判断素数     private static boolean isPrime(int n){         boolean flag true;         if(n1)           flag false;         else{             for(int i2;iMath.sqrt(n);i){             if((n%i)0 || n1){                 flag false;                 break;             }              else                flag true;           }         }         return flag;     } } 【程序3】 题目打印出所有的水仙花数所谓水仙花数是指一个三位数其各位数字立方和等于该数本身。例如153是一个水仙花数因为1531的三次方5的三次方3的三次方。 程序分析利用for循环控制100-999个数每个数分解出个位十位百位。 public class Prog3{     public static void main(String[] args){         for(int i100;i1000;i){             if(isLotus(i))                System.out.print(i );         }         System.out.println();     }     //判断水仙花数     private static boolean isLotus(int lotus){         int m 0;         int n lotus;         int sum 0;         m n/100;         n  - m*100;         sum m*m*m;         m n/10;         n - m*10;         sum m*m*m n*n*n;         if(sumlotus)             return true;         else             return false;         } } 【程序4】 题目将一个正整数分解质因数。例如输入90,打印出902*3*3*5。 程序分析对n进行分解质因数应先找到一个最小的质数k然后按下述步骤完成 (1)如果这个质数恰等于n则说明分解质因数的过程已经结束打印出即可。 (2)如果nk但n能被k整除则应打印出k的值并用n除以k的商,作为新的正整数n,重复执行第一步。 (3)如果n不能被k整除则用k1作为k的值,重复执行第一步。 public class Prog4{     public static void main(String[] args){         int n 13;         decompose(n);     }     private static void decompose(int n){         System.out.print(n);         for(int i2;in1;i){             while(n%i0 n!i){                 n/i;                 System.out.print(i*);             }             if(ni){                 System.out.println(i);                 break;             }         }     } } 【程序5】 题目利用条件运算符的嵌套来完成此题学习成绩90分的同学用A表示60-89分之间的用B表示60分以下的用C表示。 程序分析(ab)?a:b这是条件运算符的基本例子。 public class Prog5{        public static void main(String[] args){               int n -1;               try{                      n Integer.parseInt(args[0]);               }catch(ArrayIndexOutOfBoundsException e){                      System.out.println(请输入成绩);                      return;               }               grade(n);        }        //成绩等级计算        private static void grade(int n){               if(n100 || n0)                 System.out.println(输入无效);               else{                 String str (n90)?分属于A等:((n60)?分属于B等:分属于C等);                 System.out.println(nstr);               }        } } 【程序6】 题目输入两个正整数m和n求其最大公约数和最小公倍数。 程序分析利用辗除法。 public class Prog6{     public static void main(String[] args){         int m,n;         try{             m Integer.parseInt(args[0]);             n Integer.parseInt(args[1]);         }catch(ArrayIndexOutOfBoundsException e){             System.out.println(输入有误);             return;         }         max_min(m,n);     }     //求最大公约数和最小公倍数     private static void max_min(int m, int n){         int temp 1;         int yshu 1;         int bshu m*n;         if(nm){             temp n;             n m;             m temp;         }         while(m!0){             temp n%m;             n m;             m temp;         }         yshu n;         bshu / n;         System.out.println(m和n的最大公约数为yshu);         System.out.println(m和n的最小公倍数为bshu);     } } 【程序7】 题目输入一行字符分别统计出其中英文字母、空格、数字和其它字符的个数。 程序分析利用while语句,条件为输入的字符不为\n. import java.util.Scanner; public class Prog7_1{     public static void main(String[] args){         System.out.print(请输入一串字符);         Scanner scan new Scanner(System.in);         String str scan.nextLine();//将一行字符转化为字符串         scan.close();         count(str);     }     //统计输入的字符数     private static void count(String str){         String E1 [\u4e00-\u9fa5];//汉字         String E2 [a-zA-Z];         String E3 [0-9];         String E4 \\s;//空格         int countChinese 0;         int countLetter 0;         int countNumber 0;         int countSpace 0;         int countOther 0;         char[] array_Char str.toCharArray();//将字符串转化为字符数组         String[] array_String new String[array_Char.length];//汉字只能作为字符串处理         for(int i0;iarray_Char.length;i)           array_String[i] String.valueOf(array_Char[i]);         //遍历字符串数组中的元素         for(String s:array_String){             if(s.matches(E1))               countChinese;             else if(s.matches(E2))               countLetter;             else if(s.matches(E3))               countNumber;             else if(s.matches(E4))               countSpace;             else               countOther;         }         System.out.println(输入的汉字个数countChinese);         System.out.println(输入的字母个数countLetter);         System.out.println(输入的数字个数countNumber);         System.out.println(输入的空格个数countSpace);         System.out.println(输入的其它字符个数countSpace);     } } import java.util.*; public class Prog7_2{     public static void main(String[] args){       System.out.println(请输入一行字符);       Scanner scan new Scanner(System.in);       String str scan.nextLine();       scan.close();       count(str);     }     //统计输入的字符     private static void count(String str){         ListString list new ArrayListString();         char[] array_Char str.toCharArray();         for(char c:array_Char)           list.add(String.valueOf(c));//将字符作为字符串添加到list表中         Collections.sort(list);//排序         for(String s:list){             int begin list.indexOf(s);             int end list.lastIndexOf(s);             //索引结束统计字符数             if(list.get(end)s)               System.out.println(字符‘s’有(end-begin1)个);         }     } } 【程序8】 题目求saaaaaaaaaaaa...a的值其中a是一个数字。例如222222222222222(此时共有5个数相加)几个数相加有键盘控制。 程序分析关键是计算出每一项的值。 import java.util.Scanner;   public class Prog8{     public static void main(String[] args){         System.out.print(求saaaaaaaaaa...的值请输入a的值);         Scanner scan new Scanner(System.in).useDelimiter(\\s*);//以空格作为分隔符         int a scan.nextInt();         int n scan.nextInt();         scan.close();//关闭扫描器         System.out.println(expressed(2,5)add(2,5));     }     //求和表达式     private static String expressed(int a,int n){         StringBuffer sb new StringBuffer();         StringBuffer subSB new StringBuffer();         for(int i1;in1;i){           subSB subSB.append(a);           sb sb.append(subSB);           if(in)             sb sb.append();         }         sb.append();         return sb.toString();     }     //求和     private static long add(int a,int n){         long sum 0;         long subSUM 0;         for(int i1;in1;i){             subSUM subSUM*10a;             sum sumsubSUM;         }         return sum;     } } 【程序9】 题目一个数如果恰好等于它的因子之和这个数就称为完数。例如6123.编程找出1000以内的所有完数。 public class Prog9{     public static void main(String[] args){         int n 10000;         compNumber(n);     }     //求完数     private static void compNumber(int n){         int count 0;         System.out.println(n以内的完数);         for(int i1;in1;i){             int sum 0;             for(int j1;ji/21;j){                 if((i%j)0){                     sum j;                     if(sumi){                   System.out.print(i );                   if((count)%50)                     System.out.println();                 }                 }             }         }     } } 【程序10】 题目一球从100米高度自由落下每次落地后反跳回原高度的一半再落下求它在第10次落地时共经过多少米第10次反弹多高 import java.util.Scanner; public class Prog10{     public static void main(String[] args){         System.out.print(请输入小球落地时的高度和求解的次数);         Scanner scan new Scanner(System.in).useDelimiter(\\s);         int h scan.nextInt();         int n scan.nextInt();         scan.close();         distance(h,n);     }     //小球从h高度落下经n次反弹后经过的距离和反弹的高度     private static void distance(int h,int n){         double length 0;         for(int i0;in;i){             length h;             h /2.0 ;         }         System.out.println(经过第n次反弹后小球共经过length米第n次反弹高度为h米);     } } 【程序11】 题目有1、2、3、4个数字能组成多少个互不相同且无重复数字的三位数都是多少 程序分析可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。 public class Prog11{     public static void main(String[] args){         int count 0;         int n 0;         for(int i1;i5;i){             for(int j1;j5;j){                 if(ji)                   continue;                 for(int k1;k5;k){                     if(k!i k!j){                         n i*100j*10k;                       System.out.print(n );                       if((count)%50)                       System.out.println();                     }                 }             }         }         System.out.println();         System.out.println(符合条件的数共count个);     } } 【程序12】 题目企业发放的奖金根据利润提成。利润(I)低于或等于10万元时奖金可提10%利润高于10万元低于20万元时低于10万元的部分按10%提成高于10万元的部分可可提成7.5%20万到40万之间时高于20万元的部分可提成5%40万到60万之间时高于40万元的部分可提成3%60万到100万之间时高于60万元的部分可提成1.5%高于100万元时超过100万元的部分按1%提成从键盘输入当月利润I求应发放奖金总数 程序分析请利用数轴来分界定位。注意定义时需把奖金定义成长整型。 import java.io.*; public class Prog12{     public static void main(String[] args){         System.out.print(请输入当前利润);         long profit Long.parseLong(key_Input());         System.out.println(应发奖金bonus(profit));     }     //接受从键盘输入的内容     private static String key_Input(){         String str null;         BufferedReader bufIn new BufferedReader(new InputStreamReader(System.in));         try{             str bufIn.readLine();         }catch(IOException e){             e.printStackTrace();         }finally{             try{                 bufIn.close();             }catch(IOException e){                 e.printStackTrace();             }         }         return str;     }     //计算奖金     private static long bonus(long profit){         long prize 0;         long profit_sub profit;         if(profit1000000){             profit profit_sub-1000000;             profit_sub 1000000;             prize profit*0.01;         }         if(profit600000){             profit profit_sub-600000;             profit_sub 600000;             prize profit*0.015;         }         if(profit400000){             profit profit_sub-400000;             profit_sub 400000;             prize profit*0.03;         }         if(profit200000){             profit profit_sub-200000;             profit_sub 200000;             prize prize*0.05;         }         if(profit100000){             profit profit_sub-100000;             profit_sub 100000;             prize profit*0.075;         }         prize profit_sub*0.1;         return prize;     } }   【程序13】 题目一个整数它加上100后是一个完全平方数再加上168又是一个完全平方数请问该数是多少 程序分析在10万以内判断先将该数加上100后再开方再将该数加上268后再开方如果开方后的结果满足如下条件即是结果。 public class Prog13{     public static void main(String[] args){         int n0;         for(int i0;i100001;i){             if(isCompSqrt(i100) isCompSqrt(i268)){                 n i;                 break;             }         }         System.out.println(所求的数是n);     }     //判断完全平方数     private static boolean isCompSqrt(int n){         boolean isComp false;         for(int i1;iMath.sqrt(n)1;i){             if(nMath.pow(i,2)){                 isComp true;                 break;             }         }         return isComp;     } } 【程序14】 题目输入某年某月某日判断这一天是这一年的第几天 程序分析以3月5日为例应该先把前两个月的加起来然后再加上5天即本年的第几天特殊情况闰年且输入月份大于3时需考虑多加一天。 import java.util.Scanner; public class Prog14{     public static void main(String[] args){         Scanner scan new Scanner(System.in).useDelimiter(\\D);//匹配非数字         System.out.print(请输入当前日期年-月-日:);         int year scan.nextInt();         int month scan.nextInt();         int date scan.nextInt();         scan.close();         System.out.println(今天是year年的第analysis(year,month,date)天);     }     //判断天数     private static int analysis(int year, int month, int date){         int n 0;         int[] month_date new int[] {0,31,28,31,30,31,30,31,31,30,31,30};         if((year%400)0 || ((year%4)0)((year%100)!0))           month_date[2] 29;         for(int i0;imonth;i)           n month_date[i];         return ndate;     } } 【程序15】 题目输入三个整数x,y,z请把这三个数由小到大输出。 程序分析我们想办法把最小的数放到x上先将x与y进行比较如果xy则将x与y的值进行交换然后再用x与z进行比较如果xz则将x与z的值进行交换这样能使x最小。 import java.util.Scanner; public class Prog15{     public static void main(String[] args){         Scanner scan new Scanner(System.in).useDelimiter(\\D);         System.out.print(请输入三个数);         int x scan.nextInt();         int y scan.nextInt();         int z scan.nextInt();         scan.close();         System.out.println(排序结果sort(x,y,z));     }     //比较两个数的大小     private static String sort(int x,int y,int z){         String s null;         if(xy){             int t x;             x y;             y t;         }         if(xz){             int t x;             x z;             z t;         }         if(yz){             int t z;             z y;             y t;         }         s x y z;         return s;     } } 【程序16】 题目输出9*9口诀。 程序分析分行与列考虑共9行9列i控制行j控制列。 public class Prog16{     public static void main(String[] args){         for(int i1;i10;i){             for(int j1;ji1;j)                 System.out.print(j*i(j*i) );             System.out.println();         }     } } 【程序17】 题目猴子吃桃问题猴子第一天摘下若干个桃子当即吃了一半还不瘾又多吃了一个第二天早上又将剩下的桃子吃掉一半又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时见只剩下一个桃子了。求第一天共摘了多少。 程序分析采取逆向思维的方法从后往前推断。 public class Prog17{     public static void main(String[] args){         int m 1;       for(int i10;i0;i--)         m 2*m 2;       System.out.println(小猴子共摘了m桃子);     } } 【程序18】 题目两个乒乓球队进行比赛各出三人。甲队为a,b,c三人乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比c说他不和x,z比请编程序找出三队赛手的名单。 import java.util.ArrayList; public class Prog18{     String a,b,c;//甲队成员     public static void main(String[] args){         String[] racer {x,y,z};//乙队成员         ArrayListProg18 arrayList new ArrayListProg18();         for(int i0;i3;i)           for(int j0;j3;j)             for(int k0;k3;k){                 Prog18 prog18 new Prog18(racer[i],racer[j],racer[k]);                 if(!prog18.a.equals(prog18.b) !prog18.a.equals(prog18.c) !prog18.b.equals(prog18.c)                    !prog18.a.equals(x) !prog18.c.equals(x) !prog18.c.equals(z))                    arrayList.add(prog18);             }           for(Object obj:arrayList)             System.out.println(obj);     }     //构造方法     private Prog18(String a,String b,String c){         this.a a;         this.b b ;         this.c c;     }     public String toString(){         return a的对手是a  b的对手是b  c的对手是c;     } } 【程序19】 题目打印出如下图案菱形 * *** ****** ******** ****** *** * 程序分析先把图形分成两部分来看待前四行一个规律后三行一个规律利用双重 for循环第一层控制行第二层控制列。 public class Prog19{     public static void main(String[] args){         int n 5;         printStar(n);     }     //打印星星     private static void printStar(int n){         //打印上半部分         for(int i0;in;i){             for(int j0;j2*n;j){             if(jn-i)               System.out.print( );             if(jn-i jni)               System.out.print(*);           }           System.out.println();         }         //打印下半部分         for(int i1;in;i){             System.out.print( );             for(int j0;j2*n-i;j){                 if(ji)               System.out.print( );             if(ji j2*n-i-1)               System.out.print(*);             }             System.out.println();         }     } } 【程序20】 题目有一分数序列2/13/25/38/513/821/13...求出这个数列的前20项之和。 程序分析请抓住分子与分母的变化规律。 public class Prog20{     public static void main(String[] args){         double n1 1;         double n2 1;         double fraction n1/n2;         double Sn 0;         for(int i0;i20;i){           double t1 n1;           double t2 n2;           n1 t1t2;           n2 t1;           fraction n1/n2;           Sn fraction;         }         System.out.print(Sn);     } } 【程序21】 题目求12!3!...20!的和 程序分析此程序只是把累加变成了累乘。 public class Prog21{     public static void main(String[] args){         long sum 0;         for(int i0;i20;i)           sum factorial(i1);         System.out.println(sum);     }     //阶乘     private static long factorial(int n){         int mult 1;         for(int i1;in1;i)           mult * i;         return mult;     } } 【程序22】 题目利用递归方法求5!。 程序分析递归公式fnfn_1*4! public class Prog22{     public static void main(String[] args){         System.out.println(fact(10));     }     //递归求阶乘     private static long fact(int n){         if(n1)           return 1;         else           return fact(n-1)*n;     } } 【程序23】 题目有5个人坐在一起问第五个人多少岁他说比第4个人大2岁。问第4个人岁数他说比第3个人大2岁。问第三个人又说比第2人大两岁。问第2个人说比第一个人大两岁。最后问第一个人他说是10岁。请问第五个人多大 程序分析利用递归的方法递归分为回推和递推两个阶段。要想知道第五个人岁数需知道第四人的岁数依次类推推到第一人10岁再往回推。 public class Prog23{     public static void main(String[] args){         System.out.println(getAge(5,2));     }     //求第m位同志的年龄     private static int getAge(int m,int n){         if(m1)           return 10;         else           return getAge(m-1,n)n;           } } 【程序24】 题目给一个不多于5位的正整数要求一、求它是几位数二、逆序打印出各位数字。 public class Prog24{     public static void main(String[] args){         int n Integer.parseInt(args[0]);         int i 0;         int[] a new int[5];         do{             a[i] n%10;           n / 10;           i;         }while(n!0);         System.out.print(这是一个i位数从个位起各位数字依次为);         for(int j0;ji;j)           System.out.print(a[j] );     } } 【程序25】 题目一个5位数判断它是不是回文数。即12321是回文数个位与万位相同十位与千位相同。 import java.io.*; public class Prog25{     public static void main(String[] args){         int n 0;         System.out.print(请输入一个5位数);         BufferedReader bufin new BufferedReader(new InputStreamReader(System.in));         try{           n Integer.parseInt(bufin.readLine());         }catch(IOException e){             e.printStackTrace();         }finally{             try{               bufin.close();             }catch(IOException e){                 e.printStackTrace();             }         }         palin(n);     }     private static void palin(int n){         int m n;         int[] a new int[5];         if(n10000 || n99999){             System.out.println(输入的不是5位数);             return;         }else{           for(int i0;i5;i){               a[i] n%10;               n / 10;           }           if(a[0]a[4] a[1]a[3])             System.out.println(m是一个回文数);           else             System.out.println(m不是回文数);         }    } } 【程序26】 题目请输入星期几的第一个字母来判断一下是星期几如果第一个字母一样则继续判断第二个字母。 程序分析用情况语句比较好如果第一个字母一样则判断用情况语句或if语句判断第二个字母。 import java.io.*; public class Prog26{     public static void main(String[] args){         String str new String();       BufferedReader bufIn new BufferedReader(new InputStreamReader(System.in));       System.out.print(请输入星期的英文单词前两至四个字母);       try{           str bufIn.readLine();       }catch(IOException e){           e.printStackTrace();       }finally{           try{               bufIn.close();           }catch(IOException e){               e.printStackTrace();           }       }       week(str);     }     private static void week(String str){         int n -1;         if(str.trim().equalsIgnoreCase(Mo) || str.trim().equalsIgnoreCase(Mon) || str.trim().equalsIgnoreCase(Mond))           n 1;         if(str.trim().equalsIgnoreCase(Tu) || str.trim().equalsIgnoreCase(Tue) || str.trim().equalsIgnoreCase(Tues))           n 2;         if(str.trim().equalsIgnoreCase(We) || str.trim().equalsIgnoreCase(Wed) || str.trim().equalsIgnoreCase(Wedn))           n 3;         if(str.trim().equalsIgnoreCase(Th) || str.trim().equalsIgnoreCase(Thu) || str.trim().equalsIgnoreCase(Thur))           n 4;         if(str.trim().equalsIgnoreCase(Fr) || str.trim().equalsIgnoreCase(Fri) || str.trim().equalsIgnoreCase(Frid))           n 5;         if(str.trim().equalsIgnoreCase(Sa) || str.trim().equalsIgnoreCase(Sat) || str.trim().equalsIgnoreCase(Satu))           n 2;         if(str.trim().equalsIgnoreCase(Su) || str.trim().equalsIgnoreCase(Sun) || str.trim().equalsIgnoreCase(Sund))           n 0;         switch(n){             case 1:               System.out.println(星期一);               break;             case 2:               System.out.println(星期二);               break;             case 3:               System.out.println(星期三);               break;             case 4:               System.out.println(星期四);               break;             case 5:               System.out.println(星期五);               break;             case 6:               System.out.println(星期六);               break;             case 0:               System.out.println(星期日);               break;             default:               System.out.println(输入有误);               break;         }     } } 【程序27】 题目求100之内的素数 public class Prog27{     public static void main(String[] args){         int n 100;         System.out.print(n以内的素数);         for(int i2;in1;i){             if(isPrime(i))               System.out.print(i );         }     }     //求素数     private static boolean isPrime(int n){         boolean flag true;         for(int i2;iMath.sqrt(n)1;i)             if(n%i0){               flag false;               break;             }         return flag;     } } 【程序28】 题目对10个数进行排序 程序分析可以利用选择法即从后9个比较过程中选择一个最小的与第一个元素交换 下次类推即用第二个元素与后8个进行比较并进行交换。 public class Prog28{     public static void main(String[] args){         int[] a new int[]{31,42,21,50,12,60,81,74,101,93};         for(int i0;i10;i)             for(int j0;ja.length-i-1;j)                 if(a[j]a[j1]){                     int temp a[j];                     a[j] a[j1];                     a[j1] temp;                 }         for(int i0;ia.length;i)           System.out.print(a[i] );     } } 【程序29】 题目求一个3*3矩阵对角线元素之和 程序分析利用双重for循环控制输入二维数组再将a[i][i]累加后输出。 public class Prog29{     public static void main(String[] args){         int[][] a new int[][] {{100,2,3,},{4,5,6},{17,8,9}};         matrSum(a);     }     private static void matrSum(int[][] a){         int sum1 0;         int sum2 0;         for(int i0;ia.length;i)           for(int j0;ja[i].length;j){             if(ij) sum1 a[i][j];             if(ja.length-i-1) sum2 a[i][j];           }         System.out.println(矩阵对角线之和分别是sum1和sum2);     } } 【程序30】 题目有一个已经排好序的数组。现输入一个数要求按原来的规律将它插入数组中。 程序分析首先判断此数是否大于最后一个数然后再考虑插入中间的数的情况插入后此元素之后的数依次后移一个位置。 import java.util.Scanner; public class Prog30{     public static void main(String[] args){         int[] A new int[]{0,8,7,5,9,1,2,4,3,12};         int[] B sort(A);         print(B);         System.out.println();         System.out.print(请输入10个数的数组);         Scanner scan new Scanner(System.in);      int a scan.nextInt(); scan.close();         int[] C insert(a,B);         print(C);     }     //选择排序     private static int[] sort(int[] A){         int[] B new int[A.length];         for(int i0;iA.length-1;i){             int min A[i];             for(int ji1;jA.length;j){                 if(minA[j]){                     int temp min;                     min A[j];                     A[j] temp;                 }                 B[i] min;             }         }         B[A.length-1] A[A.length-1];         return B;     }     //打印     private static void print(int[] A){         for(int i0;iA.length;i)           System.out.print(A[i] );     }     //插入数字     private static int[] insert(int a,int[] A){         int[] B new int[A.length1];         for(int iA.length-1;i0;i--)           if(aA[i]){             B[i1] a;             for(int j0;ji;j)               B[j] A[j];               for(int ki2;kB.length;k)                 B[k] A[k-1];               break;           }         return B;     } } 【程序31】 题目将一个数组逆序输出。 程序分析用第一个与最后一个交换。 public class Prog31{     public static void main(String[] args){         int[] A new int[]{1,2,3,4,5,6,7,8,9,};         print(A);         System.out.println();         int[] B reverse(A);         print(B);     }     private static int[] reverse(int[] A){         for(int i0;iA.length/2;i){             int temp A[A.length-i-1];             A[A.length-i-1] A[i];             A[i] temp;         }         return A;     }     private static void print(int[] A){         for(int i0;iA.length;i)           System.out.print(A[i] );     } } 【程序32】 题目取一个整数a从右端开始的47位。 程序分析可以这样考虑 (1)先使a右移4位。 (2)设置一个低4位全为1,其余全为0的数。可用~(~04) (3)将上面二者进行运算。 import java.util.Scanner; public class Prog32{     public static void main(String[] msg){         //输入一个长整数         Scanner scan new Scanner(System.in);         long l scan.nextLong();         scan.close();         //以下截取字符         String str Long.toString(l);         char[] ch str.toCharArray();         int n ch.length;         if(n7)           System.out.println(输入的数小于7位);         else           System.out.println(截取的4~7位数字ch[n-7]ch[n-6]ch[n-5]ch[n-4]);         }     } 【程序33】 题目打印出杨辉三角形要求打印出10行如下图 程序分析 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 public class Prog33{     public static void main(String[] args){         int[][] n new int[10][21];         n[0][10] 1;         for(int i1;i10;i)           for(int j10-i;j10i1;j)             n[i][j] n[i-1][j-1]n[i-1][j1];         for(int i0;i10;i){             for(int j0;j21;j){                 if(n[i][j]0)                   System.out.print(   );                 else{                 if(n[i][j]10)                   System.out.print(  n[i][j]);//空格为了美观需要                 else if(n[i][j]100)                   System.out.print( n[i][j]);                   else                     System.out.print(n[i][j]);               }             }             System.out.println();         }     } } 【程序34】 题目输入3个数a,b,c按大小顺序输出。 程序分析利用指针方法。 import java.util.Scanner; public class Prog34{     public static void main(String[] args){         System.out.print(请输入3个数);         Scanner scan new Scanner(System.in).useDelimiter(\\s);         int a scan.nextInt();         int b scan.nextInt();         int c scan.nextInt();         scan.close();         if(ab){             int t a;             a b;             b t;         }         if(ac){             int t a;             a c;             c t;         }         if(bc){             int t b;             b c;             c t;         }         System.out.println(a b c);     } } 【程序35】 题目输入数组最大的与第一个元素交换最小的与最后一个元素交换输出数组。 import java.util.Scanner; public class Prog35{     public static void main(String[] args){         System.out.print(请输入一组数);         Scanner scan new Scanner(System.in).useDelimiter(\\s);         int[] a new int[50];         int m 0;         while(scan.hasNextInt()){             a[m] scan.nextInt();         }         scan.close(); int[] b new int[m];         for(int i0;im;i)           b[i] a[i];         for(int i0;ib.length;i)             for(int j0;jb.length-i-1;j)                 if(b[j]b[j1]){                     int temp b[j];                     b[j] b[j1];                     b[j1] temp;                 }         for(int i0;ib.length;i)           System.out.print(b[i] );       } } 【程序36】 题目有n个整数使其前面各数顺序向后移m个位置最后m个数变成最前面的m个数 import java.util.Scanner; public class Prog36{     public static void main(String[] args){         final int N 10;         System.out.print(请输入10个数的数组);         Scanner scan new Scanner(System.in);         int[] a new int[N];         for(int i0;ia.length;i)           a[i] scan.nextInt();         System.out.print(请输入一个小于10的数);         int m scan.nextInt();         scan.close();         int[] b new int[m];         int[] c new int[N-m];         for(int i0;im;i)           b[i] a[i];         for(int im,j0;iN;i,j)           c[j] a[i];         for(int i0;iN-m;i)           a[i] c[i];         for(int iN-m,j0;iN;i,j)           a[i] b[j];         for(int i0;ia.length;i)           System.out.print(a[i] );     } } 【程序37】 题目有n个人围成一圈顺序排号。从第一个人开始报数从1到3报数凡报到3的人退出圈子问最后留下的是原来第几号的那位。 import java.util.Scanner; public class Prog37{     public static void main(String[] args){         System.out.print(请输入一个整数);         Scanner scan new Scanner(System.in);         int n scan.nextInt();         scan.close();         //定义数组变量标识某人是否还在圈内         boolean[] isIn new boolean[n];         for(int i0;iisIn.length;i)           isIn[i] true;         //定义圈内人数、报数、索引         int inCount n;         int countNum 0;         int index 0;         while(inCount1){             if(isIn[index]){                 countNum;                 if(countNum3){                     countNum 0;                     isIn[index] false;                     inCount--;                 }             }             index;             if(indexn)               index 0;         }         for(int i0;in;i)           if(isIn[i])             System.out.println(留下的是(i1));     } } 【程序38】 题目写一个函数求一个字符串的长度在main函数中输入字符串并输出其长度。 import java.util.Scanner; public class Prog38{     public static void main(String[] args){         System.out.print(请输入一串字符);         Scanner scan new Scanner(System.in).useDelimiter(\\n);         String strIn scan.next();         scan.close();         char[] ch strIn.toCharArray();         System.out.println(strIn共(ch.length-1)个字符);     } } 【程序39】 题目编写一个函数输入n为偶数时调用函数求1/21/4...1/n,当输入n为奇数时调用函数1/11/3...1/n(利用指针函数) import java.util.Scanner; public class Prog39{     public static void main(String[] args){         System.out.print(请输入一个整数);         Scanner scan new Scanner(System.in);         int n scan.nextInt();         scan.close();         if(n%20)           System.out.println(结果even(n));         else           System.out.println(结果odd(n));     }     //奇数     static double odd(int n){         double sum 0;         for(int i1;in1;i2){             sum 1.0/i;         }         return sum;     }     //偶数     static double even(int n){         double sum 0;         for(int i2;in1;i2){             sum 1.0/i;         }         return sum;     } } 【程序40】 题目字符串排序。 public class Prog40{     public static void main(String[] args){         String[] str {abc,cad,m,fa,f};         for(int istr.length-1;i1;i--){             for(int j0;ji-1;j){                 if(str[j].compareTo(str[j1])0){                     String temp str[j];                     str[j] str[j1];                     str[j1] temp;                 }             }         }         for(String subStr:str)           System.out.print(subStr );     } } 【程序41】 题目海滩上有一堆桃子五只猴子来分。第一只猴子把这堆桃子凭据分为五份多了一个这只猴子把多的一个扔入海中拿走了一份。第二只猴子把剩下的桃子又平均分成五份又多了一个它同样把多的一个扔入海中拿走了一份第三、第四、第五只猴子都是这样做的问海滩上原来最少有多少个桃子 public class Prog41{     public static void main(String[] args){         int n;         n fun(0);         System.out.println(原来有n个桃子);     }     private static int fun(int i){         if(i5)           return 1;         else           return fun(i1)*51;     } } 【程序42】 题目809*??800*??9*??1 其中??代表的两位数,8*??的结果为两位数9*??的结果为3位数。求??代表的两位数及809*??后的结果。 public class Prog42{     public static void main(String[] args){         int n 0;         boolean flag false;         for(int i10;i100;i)           if(809*i800*i9*i1){             flag true;             n i;             break;           }         if(flag)           System.out.println(n);         else           System.out.println(无符合要求的数);     } } 【程序43】 题目求0—7所能组成的奇数个数。 public class Prog43{     public static void main(String[] args){         int count 0;         //声明由数字组成的数         int n 8;         //一位数         count n/2;         //两位数         count (n-1)*n/2;         //三位数         count (n-1)*n*n/2;         //四位数         count (n-1)*n*n*n/2;         //五位数         count (n-1)*n*n*n*n/2;         //六位数         count (n-1)*n*n*n*n*n/2;         //七位数         count (n-1)*n*n*n*n*n*n/2;         System.out.println(0-7所能组成的奇数个数count);     } } 【程序44】 题目一个偶数总能表示为两个素数之和。 import java.util.Scanner; public class Prog44{     public static void main(String[] args){         System.out.print(请输入一个偶数);         Scanner scan new Scanner(System.in);         int n scan.nextInt();         scan.close();         if(n%2!0){           System.out.println(您输入的不是偶数);           return;         }         twoAdd(n);     }     //偶数分解为素数之和     private static void twoAdd(int n){         for(int i2;in/21;i){             if(isPrime(i)isPrime(n-i)){                 System.out.println(n(i)(n-i));                 break;             }         }     }     //判断素数     private static boolean isPrime(int m){         boolean flag true;         for(int i2;iMath.sqrt(m)1;i){             if(m%i0){                 flag false;                 break;             }         }         return flag;     } } 【程序45】 题目判断一个素数能被几个9整除 import java.util.Scanner; public class Prog45{     public static void main(String[] args){         System.out.print(请输入一个数);       Scanner scan new Scanner(System.in);       long l scan.nextLong();       long n l;       scan.close();       int count 0;       while(n8){           n / 9;           count;       }       System.out.println(l能被count个9整除。);     } } 【程序46】 题目两个字符串连接程序 public class Prog46{     public static void main(String[] args){         String str1 lao lee;       String str2 牛刀;       String str str1str2;       System.out.println(str);     } } 【程序47】 题目读取7个数1—50的整数值每读取一个值程序打印出该值个数的。 import java.util.Scanner; public class Prog47{     public static void main(String[] args){         System.out.print(请输入7个整数(1-50));         Scanner scan new Scanner(System.in);         int n1 scan.nextInt();         int n2 scan.nextInt();         int n3 scan.nextInt();         int n4 scan.nextInt();         int n5 scan.nextInt();         int n6 scan.nextInt();         int n7 scan.nextInt();         scan.close();         printStar(n1);         printStar(n2);         printStar(n3);         printStar(n4);         printStar(n5);         printStar(n6);         printStar(n7);     }     static void printStar(int m){         System.out.println(m);         for(int i0;im;i)           System.out.print(*);         System.out.println();     } } 【程序48】 题目某个公司采用公用电话传递数据数据是四位的整数在传递过程中是加密的加密规则如下每位数字都加上5,然后用和除以10的余数代替该数字再将第一位和第四位交换第二位和第三位交换。 public class Prog48{     public static void main(String[] args){         int n 1234;         int[] a new int[4];         for(int i3;i0;i--){           a[i] n%10;           n / 10;         }         for(int i0;i4;i)           System.out.print(a[i]);         System.out.println();         for(int i0;ia.length;i){           a[i] 5;           a[i] % 10;         }         int temp1 a[0];         a[0] a[3];         a[3] temp1;         int temp2 a[1];         a[1] a[2];         a[2] temp2;         for(int i0;ia.length;i)           System.out.print(a[i]);     } } 【程序49】 题目计算字符串中子串出现的次数 public class Prog49{     public static void main(String[] args){         String str I come from County DingYuan Province AnHui.;         char[] ch str.toCharArray();         int count 0;         for(int i0;ich.length;i){             if(ch[i] )               count;         }         count;         System.out.println(共有count个字串);     } } 【程序50】 题目有五个学生每个学生有3门课的成绩从键盘输入以上数据包括学生号姓名三门课成绩计算出平均成绩将原有的数据和计算出的平均分数存放在磁盘文件stud中。 import java.io.*; public class Prog50{     //定义学生模型     String[] number new String[5];     String[] name new String[5];     float[][] grade new float[5][3];     float[] sum new float[5];     public static void main(String[] args) throws Exception{         Prog50 stud new Prog50();         stud.input();         stud.output();     }     //输入学号、姓名、成绩     void input() throws IOException{         BufferedReader br new BufferedReader(new InputStreamReader(System.in));         //录入状态标识         boolean isRecord true;         while(isRecord){             try{               for(int i0;i5;i){                   System.out.print(请输入学号);                   number[i] br.readLine();                   System.out.print(请输入姓名);                   name[i] br.readLine();                   for(int j0;j3;j){                       System.out.print(请输入第(j1)门课成绩);                       grade[i][j] Integer.parseInt(br.readLine());                   }                   System.out.println();                   sum[i] grade[i][0]grade[i][1]grade[i][2];               }                 isRecord false;             }catch(NumberFormatException e){                  System.out.println(请输入一个数字);           }         }     }     //输出文件     void output() throws IOException{         FileWriter fw new FileWriter(E://java50//stud.txt);         BufferedWriter bw new BufferedWriter(fw);         bw.write(No.  Name  grade1  grade2  grade3  average);         bw.newLine();         for(int i0;i5;i){           bw.write(number[i]);           bw.write(  name[i]);           for(int j0;j3;j)             bw.write(  grade[i][j]);           bw.write(  (sum[i]/5));           bw.newLine();         }         bw.close();     } }
http://www.zqtcl.cn/news/249687/

相关文章:

  • a站免费最好看的电影片推荐方正隶变简体可以做网站用么
  • 创同盟做网站找公司做网站需要咨询什么问题
  • 西安行业网站株洲高端网站建设
  • 优化网站流量商城网站建设软件
  • dw属于什么的网页制作工具网络建站优化科技
  • 百度网站首页的设计理念南京高新区规划建设局网站
  • 虚拟机做实验的网站网站以个人名义备案
  • 自定义表单网站网站建设营销型号的区别
  • 有个网站做彩盒的贵阳网站建设托管
  • 网站制作属于什么专业做网站需要什么配置服务器吗
  • 网站开发学习培训广州网站优化关键词公司
  • 毕节金海湖新区城乡建设局网站企业网站的步骤
  • 网站后台设计教程网站建设判断题
  • 珠海网站建设 金蝶天元建设集团有限公司李华
  • 海安市建设局网站成都官网seo技术
  • 网站建设策划书结束语wordpress付费版
  • 进口网站建设做网站用什么格式的图片
  • 青海省住房和城乡建设部网站进入网站空间
  • 做公司简介的开源网站企业seo多少费用
  • 学校网站建设工作方案昆明做网站词排名优化
  • 镇江企业做网站针对人群不同,网站做细分
  • 个人单页网站建设台州网站建设惠店
  • 专做婚礼logo的网站做搜狗pc网站快速排
  • 北京网站建设公司分享网站改版注意事项做网站需要多大空间
  • 主机网站建设制作天津西青区天气预报
  • 网站没有内容可以备案吗横向网站源码
  • 做的网站浏览器提示不安全站优化
  • dede移动端网站源码电子商务网站建设开题报告
  • 做网站价格多少优质做网站哪家好
  • 网站建设及推广服务的合同范本留言网站建设的报告