我是靠谱客的博主 醉熏小蝴蝶,这篇文章主要介绍自己的Java学习之路(三),现在分享给大家,希望可以做个参考。

题目一:

需求说明: 将 一组乱序的字符进行排序 进行升序和逆序输出。

  

基本代码:

/**
 * @筮堆
 */

package com.etc.july30.ui;
import java.util.Arrays;
public class Homework1 {
    public static void main(String[] args) {
        System.out.print("原始字符序列:");
        int i = 0;
        String[] n = new String[]{"a","b","r","t","u","e","i"};    
            for (int j = 0; j < n.length; j++) {
            System.out.print(n[j]+" ");
        }
            Arrays.sort(n);
            System.out.println();
            System.out.print("升序字符序列:");
            for ( i = 0; i < n.length ; i++) {    
            System.out.print(n[i]+" ");    
            }            
            System.out.println();
            System.out.print("降序字符序列 :");
            for (int k =n.length ; k > 0; k--) {
            System.out.print(n[k-1]+" ");    
            }
    }
}
运行截图:

题目二: 

需求说明: 将原有积分进行备份,然后赠送每位会员500积分,编写程序输出积分情况。

 

基本代码:

/**
 * @筮堆
 */
package com.etc.july30.ui;
import java.util.Scanner;
public class Homework2 {
    public static void main(String[] args) {
        int[] a = new int[6];
        System.out.println("请输入5位会员的积分");
        int i = 0;
        Scanner input = new Scanner(System.in);
        for ( i = 1; i <= 5; i++) {
            System.out.print("请输入第" + i + "位会员积分:");
             a[i] = input.nextInt();
        }
        System.out.println("序号tt历史积分tt新年积分");
        for ( i = 1; i <= 5; i++) {
            System.out.println(i+"tt" + a[i] +"tt" + (a[i]+500));    
        }
    }
}
运行截图:

 题目三:

训练要点: 复杂图形分步打印的思想 复杂的二重循环 需求说明: 如果用户输入的行数为奇数,则打印出菱形;否则提示用户输入奇数 实现思路: 1、while循环判断是否奇数 2、分步打印 难点指导: 打印菱形下半部分。

基本代码:

Homework3 类:

/**
 * @筮堆
 */
package com.etc.july30.ui;
import java.util.Scanner;
import com.etc.july30.util.Number_class;
public class Homework3 {
    public static void main(String[] args) {
        boolean f = true;
        Scanner input = new Scanner(System.in);
        int a = 0;
        System.out.print("输入菱形行数:");
        // 调用工具类中的数字判断的类
        Number_class zheng = new Number_class();
        while (f) {
            a = zheng.Zhengshu();
            int ji = a % 2;
            if ((ji == 0)) {
                System.err.println("请输入奇数:");
            } else {
                f = false;
            }
        }
        for (int i = 1; i < a / 2 + 2; i++) {
            for (int j = a / 2; j >= i; j--) {
                System.out.print(" ");
            }
            for (int j = 1; j <= i * 2 - 1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = 0; i < a / 2 + 1; i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print(" ");
            }
            for (int j = a / 2; j >= i * 2 - 1; j--) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Number_class 类:

/**
 * @筮堆
 */
package com.etc.july30.util;
import java.util.Scanner;
public class Number_class {
    public int Zhengshu(){
        System.out.println("(输入一个整数)");
        int a = 0 ;
        while(true){
            Scanner input = new Scanner(System.in) ;         
            if(input.hasNextInt()){
                a = input.nextInt() ;
                break ;
            }else{
                System.err.println("请输入数字!!!");
            }
        }
        return a ;
    }

运行截图:

题目四:

实现九九乘法表。

基本代码:

/**
 * @筮堆
 */
package com.etc.july30.ui;
public class Homework4 {
    public static void main(String[] args) {
        
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i +"*"+ j +"="+ i*j +"t");    
            }System.out.println();    
        }
    }
}

运行截图:

最后

以上就是醉熏小蝴蝶最近收集整理的关于自己的Java学习之路(三)的全部内容,更多相关自己内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部