全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2926
推到 Plurk!
推到 Facebook!

關於用array寫九九乘法表...

尚未結案
jeffccl
一般會員


發表:2
回覆:2
積分:0
註冊:2004-12-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-15 20:22:31 IP:154.20.xxx.xxx 未訂閱
以下是我用array寫出來的九九乘法表的code    
import java.util.*;    public class multiArrayTable
{        public static void main( String[] args )
    {
        int min;
        int max;
        int mult;
        Scanner scan = new Scanner( System.in );
        System.out.println( "Please enter the minimum value: " );
        min = scan.nextInt();
        System.out.println( "Please enter the maximum value: " );
        max = scan.nextInt();            int array[][] = new int[ max - min   1 ][ max - min   1 ];
        for( int k = min; k <= max; k   )
            mult = k;
            System.out.println();
        for( int j = max; j <= max; j   )
        {
            array[ mult ][ j ] = array[ mult ][ 0 ] * array[ 0 ][ j ];  // 1
           System.out.print( array[ mult ][ j ]   "\t" );   // 2
            
            
                    }
    }
}    
其他來說都沒有什麼很明顯的錯誤吧... 可是//1跟//2那兩行裡面的mult卻說unresolved 阿我第一個for loop有initialize mult = k 為什麼第二個for loop裡面的array會讀不到mult 可是我用for寫九九乘法表就沒有問題
public class multiTable
{        public static void main( String[] args )
    {
        int value;
        int min;
        int max;
        int mult;
        Scanner scan = new Scanner( System.in );
        System.out.println( "Please enter the minimum value: " );
        min = scan.nextInt();
        System.out.println( "Please enter the maximum value: " );
        max = scan.nextInt();            for( int i = min; i <= max; i   )
        {
            mult = i;
            value = mult;
            System.out.println();
            
            for( int j = min; j <= max; j   )
            {
                System.out.print( value   "\t" );
                value  = mult;
            }
        }        }
}    
在這一段code裡面的第一個for loop裡面的i所轉成的mult 第二個loop就讀的到 可是上一段code卻讀不到 請各位高手幫忙>"< 感激不盡 還有我的九九乘法表頂多只能用min = 1跟max = 9 如果用min = 1以外的input的話 比如說min = 3, max = 9 會出現如下output:
Please enter the minimum value: 
3
Please enter the maximum value: 
9    3        6        9        12        15        18        21        
4        8        12        16        20        24        28        
5        10        15        20        25        30        35        
6        12        18        24        30        36        42        
7        14        21        28        35        42        49        
8        16        24        32        40        48        56        
9        18        27        36        45        54        63
而我想要的是....
3        4        5        6        7        8        9        
4        16        20        24        28        32        36        
5        20        25        30        35        40        45        
6        24        30        36        42        48        54        
7        28        35        42        49        56        63        
8        32        40        48        56        64        72        
9        36        45        54        63        72        81
請問有什麼辦法可以debug成我想要的output?(比較完美的乘法表..) 因為我實在想不出怎麼讓"首列首行"跟其他的區域分開運作... 感激不盡..
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-15 21:22:08 IP:211.76.xxx.xxx 未訂閱
引言: 以下是我用array寫出來的九九乘法表的code
import java.util.*;    public class multiArrayTable
{        public static void main( String[] args )
    {
        int min;
        int max;
        int mult;
        Scanner scan = new Scanner( System.in );
        System.out.println( "Please enter the minimum value: " );
        min = scan.nextInt();
        System.out.println( "Please enter the maximum value: " );
        max = scan.nextInt();            int array[][] = new int[ max - min   1 ][ max - min   1 ];
        for( int k = min; k <= max; k   )
            mult = k;
            System.out.println();
        for( int j = max; j <= max; j   )
        {
            array[ mult ][ j ] = array[ mult ][ 0 ] * array[ 0 ][ j ];  // 1
           System.out.print( array[ mult ][ j ]   "\t" );   // 2
            
            
                    }
    }
}    
其他來說都沒有什麼很明顯的錯誤吧... 可是//1跟//2那兩行裡面的mult卻說unresolved 阿我第一個for loop有initialize mult = k 為什麼第二個for loop裡面的array會讀不到mult 其實Java對於使用變數值如果未初始化,是會抱怨的。 這也就是您上下兩個問題所在。 可是我用for寫九九乘法表就沒有問題
public class multiTable
{        public static void main( String[] args )
    {
        int value;
        int min;
        int max;
        int mult;
        Scanner scan = new Scanner( System.in );
        System.out.println( "Please enter the minimum value: " );
        min = scan.nextInt();
        System.out.println( "Please enter the maximum value: " );
        max = scan.nextInt();
         // 試試下列廻圈
        for( int i = min; i <= max; i   )
        {
            if ( i==min )
              mult  = 1; // first row
            else mult  = i;                value = i;                System.out.println();                for( int j = min; j <= max; j   )
            {
                System.out.print( value   "\t" );
                if ( (j==min) && (i!=min) ) value = j*i;
                value  = mult;
            }
        }
    }
}    
在這一段code裡面的第一個for loop裡面的i所轉成的mult 第二個loop就讀的到 可是上一段code卻讀不到 請各位高手幫忙>"< 感激不盡 還有我的九九乘法表頂多只能用min = 1跟max = 9 如果用min = 1以外的input的話 比如說min = 3, max = 9 會出現如下output:
Please enter the minimum value: 
3
Please enter the maximum value: 
9    3        6        9        12        15        18        21        
4        8        12        16        20        24        28        
5        10        15        20        25        30        35        
6        12        18        24        30        36        42        
7        14        21        28        35        42        49        
8        16        24        32        40        48        56        
9        18        27        36        45        54        63
而我想要的是....
3        4        5        6        7        8        9        
4        16        20        24        28        32        36        
5        20        25        30        35        40        45        
6        24        30        36        42        48        54        
7        28        35        42        49        56        63        
8        32        40        48        56        64        72        
9        36        45        54        63        72        81
請問有什麼辦法可以debug成我想要的output?(比較完美的乘法表..) 因為我實在想不出怎麼讓"首列首行"跟其他的區域分開運作... 感激不盡..
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
jeffccl
一般會員


發表:2
回覆:2
積分:0
註冊:2004-12-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-17 15:36:53 IP:154.20.xxx.xxx 未訂閱
已經了解了! 多謝:D
系統時間:2024-05-08 21:34:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!