返回列表 發帖

1217 使用者輸入值(實作jvd103)

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 3 l, b3 E8 ?/ N$ }
! d/ g$ K, G% i5 }+ V8 ^
程式中可以輸入值
$ ]% [$ y4 P! F! H6 j  ~- c: F* ~: ]6 Z: F) @( {
實際寫出 jvd103
) t# c. B) }2 a3 `1 V! B+ u3 ]- m; m7 A, o2 {' B4 Y! u2 Q9 p+ ~/ N
使用io一定要使用 try catch
  1. import java.io.* ; // input output 資料函式引入
  2. import java.util.Arrays ;

  3. public class JVD103{

  4.         public static void main(String arg[]){
  5.        
  6.        
  7.                 System.out.println("請輸入欲產生之亂數個數:");
  8.        
  9.                 int n = 0;  //輸入要產生亂數個數 並初始化
  10.                
  11.                 //使用到io 一定要加上 try catch
  12.                 try{
  13.                         InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
  14.                         BufferedReader br = new BufferedReader(isr); //資料暫存區
  15.                         n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
  16.                 }catch(Exception e){}
  17.                
  18.                
  19.                 int Num[] = new int[n];//產生n個亂數的變數
  20.                
  21.                 for(int i=0;i<n;i++){
  22.                         Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
  23.                         //System.out.println(Num[i]);
  24.                 }
  25.                 Arrays.sort(Num); //排序
  26.                
  27.                 //輸出
  28.                 for(int i=0;i<n;i++){
  29.                    System.out.print(Num[i]+"\t");
  30.                 }
  31.                
  32.         }

  33. }
複製代碼
  1. import java.util.Scanner; //輸出入
  2. import java.util.Arrays;  //陣列

  3. public class jva103{

  4.         public static void main(String args[]){
  5.        
  6.                 System.out.println("請輸入欲產生之亂數個數:");

  7.                 Scanner s = new Scanner(System.in);

  8.                 //System.out.println(s.nextInt());
  9.                
  10.                 int n = s.nextInt();
  11.                 int ar[] = new int[n];
  12.                
  13.                 //產生亂數
  14.                 for(int i=0;i<n;i++){
  15.                         ar[i] = (int)(Math.random()*1000) ;
  16.                         //System.out.println(ar[i]);
  17.                 }
  18.                 Arrays.sort(ar);
  19.                
  20.                 for(int i=0;i<n;i++){
  21.                         System.out.print(ar[i]+"\t");
  22.                 }
  23.        
  24.         }

  25. }
複製代碼

import java.util.Arrays;1 g* C) u8 B+ d- c
- J/ f- j* W+ ^" k( ^- u" _
import java.util.Scanner ;
) h* ~( K' ~: v2 {+ O) s: o1 f9 [2 I3 e5 Q6 Z
public class j103
' \$ t3 g; j6 ]) u8 `
5 y2 e* j0 m/ B% c' G{
( g/ K& y( V0 m; K* ?- B
' o5 }' c/ m& T( L" `        public static void main(String[]arg)
# k: O: R4 ?9 x( E7 ]  ^- \" v$ \3 I  I7 J  {
        {# ]* x6 n2 x# M5 _  L2 h" {

6 V1 `; k" u& U% d# r        System.out.println("請輸入欲產生之亂數個數");0 V2 V. T( P- ]3 O( P$ D, f
& k; g# H7 W( G
        Scanner s=new Scanner(System.in);
7 n5 t' L5 R) N* Z0 d1 E' s) `( _/ ]  w5 K% t/ G- I
        //System.out.println(s.nextInt());
; u1 _9 r# S) ?, `  I/ P% {
) N; |' B6 q: ]. W( K3 r$ _        int n = s.nextInt();8 N1 l6 z% r: b+ M
- C- [( v) T* |9 w; ^  d- V- E
        int ar[]=new int[n];% A# i" c/ l2 E2 t( u
7 j1 b% d5 d3 r. \, w! X- Y5 x
                for(int i=0;i<n;i++)# C' r: F& O/ P& [1 X  }4 G) H/ d
3 J  @3 c5 K; M+ W
                {
* M: d+ b2 `; A6 X' H0 _1 Q1 S0 o8 e8 }+ Q5 @
                ar[i]=(int)(Math.random()*1000);3 O) t2 b9 \0 x! B

- t* S2 d; Q' J0 p8 F1 N, g# S0 C# G                }
& V2 C! Z9 |( X# Q& t- ]) o9 R% n0 D# u& n# d
        Arrays.sort(ar);
. n0 u" {+ F& {9 ^8 r: k( j' [( y1 v1 x4 b2 m, p
                for(int i=0;i<n;i++)- l' P' g: l- G) a2 k" b! p1 g

2 l! n: X' q* k- L# k3 {: _6 B/ }                {
  Z7 Z% m7 d) ~% O- {* N7 J6 b6 @3 l& b- e
                System.out.print(ar[i]+"\n")        
7 ^" y* @! ~9 q9 t* V; u6 R% S+ P( {3 V$ j, E+ `
                $ g, t$ n3 B6 L$ D
5 x' b# L4 B0 l2 f
                }  ^/ w" u! ?/ l; {+ x

) T+ ^5 i- z9 z        }
/ p/ f, d# s3 ^. K$ F- `4 M. R5 S% c- C$ b) I" W
}
人平

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class jva103{
  4.     public static void main(String arg[]){
  5.         System.out.println("請輸入欲產生之亂數個數:");
  6.     Scanner s = new Scanner(System.in);   

  7.         int n = s.nextInt();
  8.     int ar[] = new int[n];
  9.     for(int i=0;i<n;i++){
  10.             ar[i]=(int)(Math.random()*1000);
  11.             //system.out.println(ar(i);
  12.                 }       
  13.         Arrays.sort(ar);
  14.                 for(int i=0;i<n;i++){
  15.                     System.out.print(ar[i]+"\t");               
  16.                 }
  17.     }
  18. }
複製代碼
May

TOP

  1. import java.io.*; //input output 資料涵式引入

  2. import java.util.Arrays;

  3. public class JVD103{

  4.     public static void main(String arg[]){

  5.         System.out.println("請輸入欲產生之亂數個數");

  6.             int n=0;

  7.                 try{

  8.                 InputStreamReader isr=new InputStreamReader(System.in);  //輸入資料流

  9.                 BufferedReader br=new BufferedReader(isr);  //資料暫存區

  10.                 n=Integer.parseInt(br.readLine ());

  11.                 }catch(Exception e){}

  12.                 int Num[]=new int[n];

  13.                 for(int i=0;i<n;i++){

  14.                     Num[i]=(int)(Math.random()*1000);

  15.                         System.out.println(Num[i]);

  16.                 }

  17.                

  18.                 Arrays.sort(Num);

  19.                 for(int i=0;i<n;i++){

  20.                         System.out.print(Num[i]+"\t");

  21.                 }

  22.         }

  23. }
複製代碼
人平

TOP

  1. import java.util.Arrays;
  2. import java.util.Scanner ;
  3. public class j103
  4. {
  5.         public static void main(String[]arg)
  6.         {
  7.         System.out.println("請輸入欲產生之亂數個數");
  8.         Scanner s=new Scanner(System.in);
  9.         //System.out.println(s.nextInt());
  10.         int n = s.nextInt();
  11.         int ar[]=new int[n];
  12.                 for(int i=0;i<n;i++)
  13.                 {
  14.                 ar[i]=(int)(Math.random()*1000);
  15.                 }
  16.         Arrays.sort(ar);
  17.                 for(int i=0;i<n;i++)
  18.                 {
  19.                 System.out.print(ar[i]+"\n")       
  20.                
  21.                 }
  22.         }
  23. }
複製代碼
水桶小鄭,鯰魚

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class j103
  4. {
  5.         public static void main(String arg[])
  6.         {
  7.                 System.out.println("請輸入欲產生之亂數個數:");
  8.                 Scanner s=new Scanner(System.in);
  9.                 // System.out.println(s.nextInt());
  10.                 int n=s.nextInt();
  11.                 int ar[]=new int[n];
  12.                 for(int i=0;i<n;i++)
  13.                 {
  14.                         ar[i]=(int)(Math.random()*1000);
  15.                         // System.out.println(ar[i]);
  16.                 }
  17.                 Arrays.sort(ar);
  18.                 for(int i=0;i<n;i++)
  19.                 {
  20.                         System.out.println(ar[i]+"\t");
  21.                
  22.                
  23.                 }
  24.         }
  25. }
複製代碼
★ 嘉凱~~☆

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class j103
  4. {
  5.     public static void main(String[]args)
  6.         {
  7.             System.out.println("請輸入欲產生之亂數個數:");
  8.                 Scanner s=new Scanner(System.in);
  9.                 int n=s.nextInt();
  10.                 int ar[]=new int[n];
  11.                 for(int i=0;i<n;i++)
  12.                 {
  13.                     ar[i]=(int)(Math.random()*1000);
  14.             }
  15.                 Arrays.sort(ar);
  16.                 for(int i=0;i<n;i++)
  17.                 {
  18.                     System.out.println(ar[i]+"\t");
  19.             }
  20.         }
  21. }
複製代碼
小雲雀

TOP

  1. import java.io.*; //input output 資料涵式引入
  2. import java.util.Arrays;
  3. public class JVD103{
  4.     public static void main(String arg[]){
  5.         System.out.println("請輸入欲產生之亂數個數");
  6.             int n=0;
  7.                 try{
  8.                 InputStreamReader isr=new InputStreamReader(System.in);  //輸入資料流
  9.                 BufferedReader br=new BufferedReader(isr);  //資料暫存區
  10.                 n=Integer.parseInt(br.readLine ());
  11.                 }catch(Exception e){}
  12.                 int Num[]=new int[n];
  13.                 for(int i=0;i<n;i++){
  14.                     Num[i]=(int)(Math.random()*1000);
  15.                         System.out.println(Num[i]);
  16.                 }
  17.                
  18.                 Arrays.sort(Num);
  19.                 for(int i=0;i<n;i++){
  20.                         System.out.print(Num[i]+"\t");
  21.                 }
  22.         }
  23. }
複製代碼
★ 嘉凱~~☆

TOP

import java.io.* ; // input output 資料函式引入
' ]- E. [  e4 O5 o5 v5 _+ V2 M* |9 n! q
import java.util.Arrays ;
5 T/ E! |& }+ E" j; }
4 N4 p! ?" O$ b1 ]6 N- j
5 [- k8 y  p  y+ y
) x+ L! z+ L, i  Opublic class JVD103{
9 Y# L, }  ^4 F8 j& G% D
+ B. T* @+ ^. y4 X* }) I8 A. k9 t0 }& c! c3 s, e! Z
! y: Z$ f- O! G
        public static void main(String arg[]){0 j4 n0 M1 |8 a7 C) |
) y' c0 {- I7 W* T
        ! n1 t% Y+ f4 i( [! F

- a' c* I5 G. ]5 z        " ^+ b  r1 Z& ^/ S8 h5 [9 Z
* E# \% j0 a. `1 r& o
                System.out.println("請輸入欲產生之亂數個數:");; R' {6 l9 U' {: a, T3 U
. S* l$ y0 `, m; `
        
/ ~( V/ X: W& k9 @/ e! @4 k5 W3 A7 ?" I! Y
                int n = 0;  //輸入要產生亂數個數 並初始化' O  l* D4 O3 v4 A+ r

  w" B6 e! d1 I0 D- U  H0 x. V               
4 c* W; v( M+ R1 w" Z
8 P5 F' F" X7 v  X5 R                //使用到io 一定要加上 try catch
3 }6 [' S$ j; `) f  B& u3 [, d" h( \1 i% i( U* D
                try{: q: ]2 H+ H- l9 a$ N2 P( k
1 R5 S8 h9 Y) \9 t: R
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
& g9 l, d/ S" Z- r; d( J2 x) D" a5 ]) S+ c! `$ ~- C- I
                        BufferedReader br = new BufferedReader(isr); //資料暫存區( z( Y% |8 D( L) O8 v

7 x1 Q, G3 F; D; x$ Z, t                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
. U9 ?3 T3 A/ G% d5 m+ ?5 N' F! H) X# l' V
                }catch(Exception e){}
- x4 J1 t. \$ W. S( J) D" B' Z
' o8 l$ u8 {/ g/ f/ K7 U                1 l9 B' k0 u: g5 d0 w8 U1 p
) T- N+ S! s" I% d( E* B( G" B
                  l2 X2 W: N8 J5 h& V
- @: o% {7 [4 U( X( P% Y  B( U4 U0 A
                int Num[] = new int[n];//產生n個亂數的變數
' A0 o5 o6 a) G, d) [5 g7 u1 G' ?0 v, F4 l6 |. s: D
               
( G7 t$ A* e, P# V; C/ |% a8 T/ C, |* h
) A0 W- S1 W, z# \                for(int i=0;i<n;i++){
6 P8 K8 Q+ f" i* J" q  M5 y0 I  e! j
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)' y, U/ z# }0 u6 D! W
7 }+ v+ Q' f5 Y9 O7 q
                        //System.out.println(Num[i]);
+ i* m0 W2 n$ B& t  ?, R6 b" f" `' s) ^6 H" |8 |8 c
                }, Z2 L# V- X* e6 _  Y, ^5 u

# c/ ~8 f/ `6 c( H                Arrays.sort(Num); //排序
  V7 A2 n' ~' w" B$ Y1 ]8 }+ |
% Z2 t9 P8 K7 b                3 [. L( [3 y) k" j" q# G* \
+ G. Q2 t& Z# W% |
                //輸出
8 S" a  Y1 p7 l& Q0 t
. J5 F, {) _0 i) \- [                for(int i=0;i<n;i++){
3 a6 I$ J0 ^8 O6 u: P( g: J6 ~0 }6 N4 j
                   System.out.print(Num[i]+"\t");9 ^/ L* G1 V+ a$ |3 A1 q, y/ \
  \3 M3 j% e/ S8 I4 C9 W& D5 o
                }. Q' e  ~& E* Y0 B

# T: T9 v: Y( Q  B5 z6 _                + c4 p) k( D* f% v( F9 r% r

* r1 j. W& D( I) r7 O        }
$ B1 H# C, Z3 }8 y! @
* H# n' o4 w. Q6 h1 L) w
; `& e; v$ e2 W  |
+ p$ r9 |5 C& h}
人平

TOP

返回列表