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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 墨晓生 中级黑马   /  2016-8-18 19:00  /  1137 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

(1)分析以下需求,并用代码实现:
        (1)已知一个三位数,请分别获取该三位数上每一位的数值
        (2)例如:123的个位、十位、百位,分别是3、2、1
        (3)打印格式"数字123的个位是 3, 十位是 2, 百位是 1"
        */
         
        public class Text{
        public static void main(String[] args) {
                int num = 456;
                int bai = num / 100;
                int shi = num / 10 % 10;
                int ge = num % 10;
                System.out.println("数字"+num+"的个位是"+ge+",十位是"+shi+",,百位是"+bai);
            }
        }
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(2)编写程序,生成5个1至10之间的随机整数,并打印结果到控制台。
*/

import java.util.Random;
public class Text{
        public static void main(String[] args){
                Random r = new Random();
                for (int i = 0; i < 5;i ++){
                        int s = r.nextInt(10)+1;
                        System.out.println(s);
                }
        }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(3)计算1-100之间的质数有多少个?将质数以及质数总数打印在控制台。
  //质数:只能被1和本身整除的数.


   public class Text_01{
           public static void main (String[] args){
        int count = 0;
                aa:
                for(int i = 2; i < 101; i++) {
                        for(int j = 2; j < i; j++) {
                                if(i%j == 0) {
                                        continue aa;
                                }
                        }
                        count++;
                        System.out.println(i);
                }
               
                System.out.println("----------------");
           System.out.println(count);
           }
   }
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(4)编写程序,打印1到100之内的整数,但数字中包含7的要跳过


  public class Text_02{
        public static void main(String[] args){
                for(int i = 0;i <101;i++){
                        if (i % 10 == 7 || i / 10 == 7){
                                continue;
                        }
                 System.out.println(i);
                }
        }
        }
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(50我国最高山峰是珠穆朗玛峰,8848米。现在我有一张足够大的纸,它的厚度是0.01米。请问,我折叠多少次,可以折成珠穆朗玛峰的高度。
public class Text_03{
        public static void main(String[] args){
                double zhi = 0.01;
                int count = 0;
                while (zhi < 8848){
                        zhi = zhi * 2;d
                        count++;
                }
            System.out.println(count);
        }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(6)编写代码实现如下内容:if语句实现考试成绩分等级
        [90-100]        A等。
        [80-90)         B等。
        [70-80)         C等。
        [60-70)         D等。
        [0-60)          E等。
        请根据给定成绩,输出对应的等级。
        说明:"["表示包含,")"表示不包含

       
        public class Text{
                public static void main(String[] args){
                int grade = 70;
                if ( grade >90){
                        System.out.println("A等");
                }else if ( grade >80){
                        System.out.println("B等");
                }else if ( grade >70){       
                    System.out.println("C等");
                }else if ( grade >60){
                        System.out.println("D等");
                }else{
                        System.out.println("E等");
            }
          }
        }
------------------------------------------------------------------------------------------------------------------------------------------------------------------
(7)分析以下需求,并用代码实现:
(1)根据工龄(整数)给员工涨工资(整数),工龄和基本工资通过键盘录入
(2)涨工资的条件如下:                [10-15)     +5000                [5-10)      +2500                [3~5)       +1000                [1~3)       +500                [0~1)       +200
(3)如果用户输入的工龄为10,基本工资为3000,程序运行后打印格式"您目前工作了10年,基本工资为 3000元, 应涨工资 5000元,涨后工资 8000元"       

import java.util.Scanner;
public class FourText_01{
        public static void main(String[] args){
       
                Scanner sc = new Scanner(System.in);
                int x = sc.nextInt();
                if (x < 15 & x>=10)
                {
                        System.out.println("您目前工作了"+x+"年,基本工资为 3000元, 应涨工资 5000元,涨后工资 8000元");
                }else if(x < 10 & x >=5){
                        System.out.println("您目前工作了"+x+"年,基本工资为 3000元, 应涨工资 2500元,涨后工资 5500元");
                }else if(x < 5 & x >=3){
                        System.out.println("您目前工作了"+x+"年,基本工资为 3000元, 应涨工资 1000元,涨后工资 4000元");
                }else if(x < 3 & x >=1){
                        System.out.println("您目前工作了"+x+"年,基本工资为 3000元, 应涨工资 500元,涨后工资 3500元");
                }else if(x < 1 & x >=0){
                        System.out.println("您目前工作了"+x+"年,基本工资为 3000元, 应涨工资 200元,涨后工资 3200元");
                }else {
                        System.out.println("输入的工龄无效");
                }
        }
               
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------

(8)案例
        A:二维数组遍历获取到每一个值
        int[][] intArr = {{12,3,8},{11,8,32,7},{13,44,55}};
        B:公司年销售额求和
                某公司按照季度和月份统计的数据如下:单位(万元)
                第一季度:22,66,44
                第二季度:77,33,88
                第三季度:25,45,65
                第四季度:11,66,99


*/


   /*(A)
   public class Text_09{
           public static void main(String[] args){
                  int[][] arr = {{12,3,8},{11,8,32,7},{13,44,55}};
        for(int i = 0 ; i < arr.length;i++){
                        for(int j = 0 ;j < arr[i].length; j++){
                                System.out.println(arr[i][j]);
                        }
                System.out.println();               
                }                  
           }
   }
*/

public class Text_09{
        public static void main(String[] args){
                int[][] arr = {  {22,66,44} , {77,33,88} ,{25,45,65},{11,66,99} };
               
                int sum = 0 ;
                int groupSum = 0 ;
               
                for(int i = 0 ; i < arr.length ; i++){
                        for(int j = 0 ; j < arr[i].length ; j++){
                       
                                groupSum += arr[i][j];
                        }
                        System.out.println("季度总金额 "+groupSum);
                       
               
                        sum += groupSum;
                       
                        groupSum = 0;
                }
                System.out.println("年销售总金额 "+sum);
        }
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------

(9)分析以下需求,并用代码实现:
        (1)键盘录入三个整数,按照从小到大的顺序输出
        (2)如果用户输入的是3 2 1,程序运行后打印格式"按照从小到大排序后的顺序为:1 2 3"

*/

//(1)
import java.util.Scanner;
public class HomeWork3 {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入第一个数");
                int a = sc.nextInt();
                System.out.println("请输入第二个数");
                int b = sc.nextInt();
                System.out.println("请输入第三个数");
                int c = sc.nextInt();
               
                if(a<b) {
                        if(b<c) {
                                System.out.println("按照从小到大排序后的顺序为:"+a+" "+b+" "+c+"");
                        } else if(a < c) {//a < b   c < b  a<c
                                System.out.println("按照从小到大排序后的顺序为:"+a+" "+c+" "+b+"");
                        } else {//a < b   c < b    c< a
                                System.out.println("按照从小到大排序后的顺序为:"+c+" "+a+" "+b+"");
                        }
                } else {//b<a
                        if(a<c) {//b<a a < c
                                System.out.println("按照从小到大排序后的顺序为:"+b+" "+a+" "+c+"");
                        } else if(b < c) {//b <a    c < a   b< c
                                System.out.println("按照从小到大排序后的顺序为:"+b+" "+c+" "+a+"");
                        } else {//b < a     c < a    c < b
                                System.out.println("按照从小到大排序后的顺序为:"+c+" "+b+" "+a+"");
                        }
                }
        }
}




/*(2)
public class Ha{
        public static void main(String[] args){
                int a,b,c;
                int t;
                counta> > b >> c;
                if(a > b){
                        t = a; a = b; b = t;
                }
                if(a > c){
                         t = a ; a = c ; c = t;
                }
                if ( b >c){
                        t = b; b = c; c = t;
                }
                cout;
                System.out.println()
               
                }
        }
        */
------------------------------------------------------------------------------------------------------------------------------------------------------------------(10)打印nn乘法表

         public class Main {
                public static void main(String[] args){
            for(int i=1; i<10; i++){
                  for(int j=1; j<=i; j++){
                     System.out.print(j + "x" + i + "=" + (j*i));
                    System.out.print(" ");
                     }
                    System.out.println("");

         }
    }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马