A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

10个题目见附件。

myTest.zip

4.99 KB, 下载次数: 34

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
第一和第九题答案

pengguo666.rar

1.62 KB, 下载次数: 34

评分

参与人数 1技术分 +2 收起 理由
耀阳圣尊 + 2

查看全部评分

回复 使用道具 举报
来挣分咯,嘿嘿,官方辛苦了。
回复 使用道具 举报
忙了两个半小时终于做完了

江州刺史的答案.zip

17.87 KB, 阅读权限: 100, 下载次数: 1

评分

参与人数 1技术分 +9 收起 理由
耀阳圣尊 + 9 第八题,不是用递归

查看全部评分

回复 使用道具 举报
正在做  技术分是我的喽  
回复 使用道具 举报
这是我的大作。略有不足,多多指教。共勉学习

answer.zip

16.38 KB, 下载次数: 32

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
/**
*01、  判断101-200之间有多少个素数,并输出所有素数。?
* */

package feng;

public class Test1 {

        public static void main(String[] args) {
                boolean flag = true;
                int sum = 0;
                for (int i = 100; i < 200; i++) {
                        for (int j = 2; j < i; j++) {
                                if (i % j == 0) {
                                        flag = false;
                                        break;
                                }
                        }
                        if (flag) {
                                sum++;
                                System.out.println(i);
                        }
                        flag = true;
                }
                System.out.println("总共有" + sum + "个");
        }

}
/**
* 02、“将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
* */

package feng;

public class Test2 {
        public static void main(String[] args) {
                int n = 90;
                decompose(n);
        }

        private static void decompose(int n) {
                System.out.print(n + "=");
                for (int i = 2; i <= n; i++) {
                        while (n % i == 0 && n != i) {
                                n = n / i;
                                System.out.print(i + "*");
                        }
                        if (n == i) {
                                System.out.println(i);
                                break;
                        }
                }
        }
}

/**
* 03、输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
*/

package feng;

import java.util.Scanner;

public class Test3 {
        public static void main(String[] args) {
                int num1 = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                Scanner sc = new Scanner(System.in);
                String str = sc.nextLine();
                for (int i = 0; i < str.length(); i++) {
                        char ch = str.charAt(i);
                        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
                                num1++;
                        } else if (ch >= '0' && ch <= '9') {
                                num2++;
                        } else if (ch == ' ') {
                                num3++;
                        } else {
                                num4++;
                        }
                }
                System.out.println("字母有" + num1 + "个。");
                System.out.println("数字有" + num2 + "个。");
                System.out.println("空格有" + num3 + "个。");
                System.out.println("其他字符有" + num4 + "个。");
        }
}

/**
* 04、 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
* */

package feng;

import java.util.Scanner;

public class Test4 {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个整数");
                int n = sc.nextInt();
                int sum = 0;
                int a = 2;
                for (int i = 0; i < n; i++) {
                        sum = sum + a;
                        a = a * 10 + 2;
                }

                System.out.println(sum);
                sc.close();
        }
}

/**
* 05、有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
* */

package feng;

public class Test5 {
        public static void main(String[] args) {
                int temp = 0;
                for (int i = 1; i <= 4; i++) {
                        for (int j = 1; j <= 4; j++) {
                                for (int k = 1; k <= 4; k++) {
                                        if (i != j && j != k && i != k) {
                                                temp = i * 100 + j * 10 + k;
                                                System.out.print(temp + ",");
                                        }
                                }
                        }
                }
        }
}

/**
* 06、给一个不多于5位的正整数。要求:一、它是几位数,二、逆序打印出各位数字
* */

package feng;

import java.util.Scanner;

public class Test6 {

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个整数");
                int num = sc.nextInt();

                int count = 0;
                while (num != 0) {
                        count++;
                        int temp = num % 10;
                        System.out.print(temp);
                        num = num / 10;
                }
                System.out.println();
                System.out.println("它是" + count + "位数");
                sc.close();
        }

}

/**
* 07、输入三个整数x、y、z,把这三个数由小到大输出。
* */

package feng;

import java.util.Arrays;
import java.util.Scanner;

public class Test7 {

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个整数");
                int num1 = sc.nextInt();
                int num2 = sc.nextInt();
                int num3 = sc.nextInt();

                int[] arr = new int[] { num1, num2, num3 };

                Arrays.sort(arr);

                for (int i = 0; i < arr.length; i++) {
                        System.out.println(arr[i]);
                }

                sc.close();

        }

}

/**
* 08、利用递归方法求5!
*
* */

package feng;

public class Test8 {
        public static void main(String[] args) {
                int sum = factorial(5);
                System.out.println(sum);
        }

        // 阶乘的方法
        public static int factorial(int i) {
                if (i == 1) {
                        return 1;
                }
                int sum = i * factorial(i - 1);
                return sum;
        }
}

/**
* 09、一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
* */

package feng;

public class Test9 {
        public static void main(String[] args) {
                int num = 12321;
                String str = Integer.toString(num);
                StringBuffer sb = new StringBuffer();
                sb.append(str);
                sb.reverse();

                String strNew = sb.toString();

                boolean b = str.equals(strNew);

                System.out.println(b);

        }
}

/**
* 10、 将一个数组逆序输出,(不能使用API的方法)。
* */

package feng;

public class Test10 {

        public static void main(String[] args) {
                int[] arr = { 9, -1, 10, 1, 20, -12 };
                int count = arr.length / 2;
                for (int i = 0; i <= count; i++) {
                        int temp = arr[i];
                        arr[i] = arr[arr.length - 1 - i];
                        arr[arr.length - 1 - i] = temp;
                }

                for (int i = 0; i < arr.length; i++) {
                        System.out.println(arr[i]);
                }
        }

}



奇峰.rar

4.12 KB, 下载次数: 30

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
我的作业

src.zip

5.06 KB, 下载次数: 28

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
支持黑马,,,,赞赞赞   。。
回复 使用道具 举报
没做完

Test1.zip

1.56 KB, 阅读权限: 100, 下载次数: 1

评分

参与人数 1技术分 +3 收起 理由
耀阳圣尊 + 3

查看全部评分

回复 使用道具 举报
大家加油哦
回复 使用道具 举报
本帖最后由 菜鸟学徒 于 2015-8-3 22:01 编辑

01、  判断101-200之间有多少个素数,并输出所有素数。?
class Demo1
  {
          public static void main(String[]args)
          {
                  int m=101;
                  int n=200;
                  int count=0;
                  for (int i=m;i<n ;i++ )
                  {
                          if(isSuShu(i))
                          {
                                  count++;
                                  System.out.print(i+" ");
                                  if (count%10==0)
                                  {
                                          System.out.println();
                                  }
                          }
                  }
                  System.out.println();
          System.out.println("在"+m+"和"+n+"之间有"+count+"个素数");
          }

          private static  boolean isSuShu(int n)
          {
                  boolean flag=true;
                  if (n==1)
                  {
                          flag=false;
                  }
                  else
                  {
                          for (int i=2;i<Math.sqrt(n) ; i++)
                          {
                                  if((n%i==0)||n==1)
                                  {  
                                      flag=false;
                                      break;
                                  }
                                  else
                                          flag=true;
                          }
                  }
                          return flag;
          }
  }
02、将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
public class Demo2
{
        public static void main(String[] args)
        {
                int n = 13;
                fen(n);
        }
        private static void fen(int n)
        {
                System.out.print(n+"=");
                for(int i=2;i<n+1;i++)
                {
                        while(n%i==0 && n!=i)
                        {
                                n/=i;
                                System.out.print(i+"*");
                        }
                        if(n==i)
                        {
                                System.out.println(i);
                                break;
                        }
                }
        }
}
03、输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

import java.util.Scanner;
public class Demo3{
        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 i=0;i<array_Char.length;i++)
                  array_String = String.valueOf(array_Char);
                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);
        }
}
04、 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
import java.util.Scanner;
public class Demo4{
        public static void main(String[] args){
                System.out.print("求s=a+aa+aaa+aaaa+...的值,请输入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 i=1;i<n+1;i++){
                  subSB = subSB.append(a);
                  sb = sb.append(subSB);
                  if(i<n)
                    sb = sb.append("+");
                }
                sb.append("=");
                return sb.toString();
        }
        private static long add(int a,int n){
                long sum = 0;
                long subSUM = 0;
                for(int i=1;i<n+1;i++){
                        subSUM = subSUM*10+a;
                        sum = sum+subSUM;
                }
                return sum;
        }
}
05、有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
public class Demo5{
        public static void main(String[] args){
                int count = 0;
                int n = 0;
                for(int i=1;i<5;i++){
                        for(int j=1;j<5;j++){
                                if(j==i)
                                  continue;
                                for(int k=1;k<5;k++){
                                        if(k!=i && k!=j){
                                                n = i*100+j*10+k;
                                          System.out.print(n+" ");
                                          if((++count)%5==0)
                                          System.out.println();
                                        }
                                }
                        }
                }
                System.out.println();
                System.out.println("符合条件的数共:"+count+"个");
        }
}
06、给一个不多于5位的正整数。要求:一、它是几位数,二、逆序打印出各位数字。
public class Demo6{
        public static void main(String[] args){
                int n = Integer.parseInt(args[0]);
                int i = 0;
                int[] a = new int[5];
                do{
                          a = n%10;
                          n /= 10;
                          ++i;
                }while(n!=0);
                System.out.print("这是一个"+i+"位数,从个位起,各位数字依次为:");
                for(int j=0;j<i;j++)
                  System.out.print(a[j]+" ");
        }
}
07、输入三个整数x、y、z,把这三个数由小到大输出。
import java.util.Scanner;
public class Demo7{
        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(x>y){
                        int t = x;
                        x = y;
                        y = t;
                }
                if(x>z){
                        int t = x;
                        x = z;
                        z = t;
                }
                if(y>z){
                        int t = z;
                        z = y;
                        y = t;
                }
                s = x+" "+y+" "+z;
                return s;
        }
}
08、利用递归方法求5!。
public class Demo8
{
        public static void main(String[] args)
        {
                System.out.println(fact(10));
        }
        private static long fact(int n)
        {
                if(n==1)
                  return 1;
                else
                  return fact(n-1)*n;
        }
}
09、一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
import java.util.*;
public class Demo9
{
        public static void main(String[] args)        
   {
        Scanner s = new Scanner(System.in);
         int a;
        do
        {
        System.out.print("请输入一个5位正整数:");
         a = s.nextInt();
         }while(a<10000||a>99999);
         String ss =String.valueOf(a);
        char[] ch = ss.toCharArray();
         if(ch[0]==ch[4]&&ch[1]==ch[3])
        {
         System.out.println("这是一个回文数");
        }
        else
       {
        System.out.println("这不是一个回文数");
        }
    }
}



10、 将一个数组逆序输出,(不能使用API的方法)。
import java.util.Scanner;
class NiShuZu
{
         public static void main(String[]args)
         {
                 Scanner s=new Scanner(System.in);
                 int []a =new int[20];
                 System.out.println("请输入多个正整数(输入-1表示结束):");
                 int i=0,j;
                 do
                 {
                         a=s.nextInt();
                         i++;
                 }
                 while (a[i-1]!=-1);
                 System.out.println("你输入的数组为:");
                 for ( j=0;j<i-1 ;j++ )
                 {
                         System.out.print(a[j]+" ");
                 }
                 System.out.println("\n数组逆序输出为:");
                 for ( j=i-2;j>=0 ;j=j-1 )
                 {
                         System.out.print(a[j]+" ");
                 }
         }
}

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
这么大的诱惑啊

技术分啊.zip

2.46 KB, 下载次数: 37

求技术分啊

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
赞赞赞大爱呀
回复 使用道具 举报
朋友传给我时,没注意到版块是Java,所以这些答案都是以C语言撰写。如果不合规矩而没有技术分我也已经有心理准备,谢谢拨空阅读!

JavaBlockAns.zip

208.65 KB, 下载次数: 32

点评

虽然我这看不了,但是还是给你1分鼓励鼓励。在对应的ios板块有题  发表于 2015-8-6 11:08

评分

参与人数 1技术分 +1 收起 理由
耀阳圣尊 + 1

查看全部评分

回复 使用道具 举报
只做了1,2,4,5,6,7,9,10共8题

黑马论坛四周年庆典-java代码.zip

5.71 KB, 下载次数: 27

评分

参与人数 1技术分 +8 收起 理由
耀阳圣尊 + 8

查看全部评分

回复 使用道具 举报
题目答复

答复.zip

2.39 KB, 下载次数: 34

评分

参与人数 1技术分 +9 收起 理由
耀阳圣尊 + 9

查看全部评分

回复 使用道具 举报
现在回复还不晚吧  

代码.zip

2.41 KB, 下载次数: 34

答案

评分

参与人数 1技术分 +10 收起 理由
耀阳圣尊 + 10

查看全部评分

回复 使用道具 举报
zk338142 来自手机 中级黑马 2015-8-3 22:25:02
239#
为啥我提交答案的190楼被删了,技术分也没有?为什么啊?
回复 使用道具 举报
exam.zip (17.65 KB, 下载次数: 46)

评分

参与人数 1技术分 +9 收起 理由
耀阳圣尊 + 9

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马