zoukankan      html  css  js  c++  java
  • Java基础之两个小算法


    博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 


    遍历二维数组

    package com.blog.test;
    
    public class TestLoop {
    	public static void main(String[] args) {
    		int cal = 0;
    
    		String[][] array = new String[7][6];
    
    		for (int i = 0; i < array.length; i++) {// 遍历纵向的数据
    
    			for (int j = 0; j < array[i].length; j++) {// 遍历横向的数据
    
    				System.out.print(array[i][j] + "a" + "\t");
    
    				++cal;
    
    				if (cal % 7 == 0) {
    
    					System.out.println();
    
    				}
    
    			}
    
    		}
    	}
    }
    


    输入出“请输入一个数字:”--》判断--》是数字的话,打出该数字;不是的话,再输出“请输入数字:”!
    package com.blog.test;
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    public class TestCalculate {
    	static TestCalculate b = new TestCalculate();
    
    	public static void main(String[] args) throws Exception {
    		b.isNumber();
    	}
    
    	public String deal() throws Exception {
    		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    		System.out.print("請輸入一列数字: ");
    		String a = buf.readLine();
    		return a;
    	}
    
    	public void isNumber() throws Exception {
    		String str = b.deal();
    		boolean isNumber = true;
    		char[] ch = str.toCharArray();
    		for (int k = 0; k < ch.length && isNumber == true; k++) {
    			isNumber = Character.isDigit(ch[k]);
    			if (isNumber) {
    				System.out.println("您输入的数字是:" + str);
    				int c = Integer.parseInt(str);
    				for (int i = c; i > 0; i--) {
    					for (int j = i; j > 0; j--) {
    						System.out.print(j + " ");
    					}
    					System.out.println();
    				}
    				break;
    			} else {
    				b.isNumber();
    			}
    		}
    	}
    
    }







  • 相关阅读:
    Daily Recording 2020/01/09(关键词:1月01版,RouterScan)
    SQL语句技巧(转)
    实施的WinForms键盘快捷键方法
    日常问题汇总(1) 分组筛选
    设计模式 创建型设计模式
    TSQL查询逻辑查询处理
    无法嵌入互操作类型错误处理
    设计模式 创建模式
    设计模式 结构模式
    设计模式 行为模式
  • 原文地址:https://www.cnblogs.com/fengju/p/6174531.html
Copyright © 2011-2022 走看看