返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
# V6 a" |, t" t/ D
1 \0 ~! o; V2 u9 |0 {$ [程式中可以輸入值
) G! ], b# J# _2 G" H/ s* ]* Z8 g5 ]$ S/ \$ t+ U
實際寫出 jvd103) R1 E; c! A% f; X: D5 t& f; o
' D; c) s+ T2 p9 i) x
使用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.io.* ; // input output 資料函式引入
0 p. _, [* }, P$ F1 C
) k- R9 x% g! ]1 S6 p' L! iimport java.util.Arrays ;
5 D  Y+ Z" u& F1 x' v$ e' O
) ?0 p# e; i) u
6 A+ c* B) y3 E4 ]6 E3 r
7 y/ ^7 R: f. ~( k0 W( j2 Ppublic class JVD103{
8 v( L* I9 C2 l; Q7 z; ]0 N* L3 u9 r2 x  Q# p

4 g/ O3 x; ]2 g( y" O3 U5 z3 }+ K9 P3 y( H$ f
        public static void main(String arg[]){
# J- r: [2 @; E9 O, T& f
- Y6 H8 \1 R! l. n) q4 R* e2 @/ ]        ! Q% O/ s, k+ R  P3 ~

3 _  O$ J3 M6 q% y        
  p* {" }$ ^5 |/ W) U( U; h/ a
/ A4 A( r. ^$ i: d! k# ~0 l                System.out.println("請輸入欲產生之亂數個數:");* q: j4 Y/ w& l6 t/ r
& |/ G' s: ~! L# Z# Y$ x# S
        
2 U9 t* H: n! D* J" W7 w' l$ M
) G( j7 `4 n* k" E" i1 h9 R: W                int n = 0;  //輸入要產生亂數個數 並初始化& f9 K: h3 w+ o" I% r

* w# D% R/ p2 c# C               
  x) }% F- M. ]) c- F* Y# J+ n7 F- ^' i& c7 t$ u& ?
                //使用到io 一定要加上 try catch
; v) {" Z3 I9 ~0 d
( A& E$ g1 i+ l5 {2 A$ O- E                try{
' G6 u+ [" ~$ u- k: d
' T  c0 x5 A+ }- l+ v+ Q                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流5 @0 ?3 C2 z. \
9 w$ ~* K+ X# v; r8 e9 d8 y6 |
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
% B( Q6 [( \2 x) q+ T( F, X& @1 \3 |9 x- U+ p/ J9 M9 s
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)* \6 A( D" W8 P5 Z

+ x* r2 V4 ]$ Q; }' @                }catch(Exception e){}
9 z5 S8 ~% k3 E8 O" H9 g& b+ H( F
               
. h* Q3 k) p7 Z- ?3 N4 x9 i# {. N! d4 ^9 y, g0 J% @
               
) P% t8 T9 C* P4 i/ I+ R% b. n, D
& R; ^5 d# i. _% x& F" _                int Num[] = new int[n];//產生n個亂數的變數
$ h* i% O' S* N( S  \6 \7 s8 |1 m$ H- E- Z1 O6 B% N
               
. X0 ]% ~; x3 w2 o1 C( Q; Q* B9 ^7 t& d: p7 I, Y9 g+ f6 C
                for(int i=0;i<n;i++){
' Y7 u. u4 l* V/ c* ^! G+ B; H* w% J5 G: |  g
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
0 v6 [, c) ~8 G
% v/ G3 F! w) f, z/ b% I' w                        //System.out.println(Num[i]);9 L  X, s& f! c5 \. G1 t) ?

9 v5 E+ b$ T( _+ i5 C! t- Q1 Q                }- k, {4 ~9 h* Y: V% A4 g5 m

$ e  p% g6 B4 j; t                Arrays.sort(Num); //排序2 q% L- F' |2 N
- p* N; X$ F2 W; P
               
: C# f  t$ d/ X6 l1 ?! A& t- _8 G- C4 ]* j
                //輸出3 J8 a" H% i. W  ~$ R
8 }. K) f1 o# V( [
                for(int i=0;i<n;i++){. Y: V) n7 V% v. D* k0 u5 i
0 b1 V8 V* K" ]6 Q# I
                   System.out.print(Num[i]+"\t");
5 A9 Y3 J* i8 }4 Y7 n3 }! C) l: u# X/ w+ F/ o
                }# l. `% R8 W7 q" }6 [
1 b# j1 u5 {# W6 R, j
               
4 _1 h7 S! ~0 B8 g5 l* _7 A5 p( v7 Z/ q# P( o
        }
+ o' c$ f* `- A" z# q. r* I3 _) i9 Z
1 Q) c0 M, j/ n' J* [: \$ @
& w. _6 q1 s* U0 l* d- }0 Y' F/ M. a0 V2 J
}
人平

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.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.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.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.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.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

import java.util.Arrays;
; L' b: B2 s0 q+ I5 ^% A' f$ j
- j) Q* n, z' ?" X2 a; B( J) a8 ?import java.util.Scanner ;7 C% K; @. |6 d' v% j% s# u* H* e8 U

* c+ h3 g+ V; ~% i" lpublic class j103
8 N/ p+ G7 D9 W8 r- h2 y5 p
0 P1 K, w" b, C0 ]0 `8 r0 o5 }{: e# S- ]. G. u; Z; u+ V
6 l9 S/ j, G, J, v+ P+ o9 Y
        public static void main(String[]arg)
4 }8 X' \9 U2 Z. p7 D) c: T+ t, Q; t2 N; C
        {. Y  F' A5 \- b9 L
$ I! Z5 \' k9 d  W0 S* @0 `
        System.out.println("請輸入欲產生之亂數個數");
( C& ^; u5 H% A  k1 A! |2 w0 W' y6 l0 e1 J1 m' m
        Scanner s=new Scanner(System.in);( l; f/ h4 h3 M8 K, k
) ?- s! M( i2 z6 F* S* G- k
        //System.out.println(s.nextInt());
+ }# k' R- `; y0 t( o: J8 _/ s6 c" i, G. W! e, G8 W
        int n = s.nextInt();) |8 L1 ?0 w  N% e$ @7 G

. n+ e/ M% B; [9 P0 Y        int ar[]=new int[n];! w4 E: |8 V8 m# y

) q$ V- J/ p% Z% S  v5 [                for(int i=0;i<n;i++)* V1 D! s  t( l3 ~/ X
; V4 v4 x2 ~* g
                {' j- K8 `$ c. X; ^2 q$ Q; C5 w

; W& }/ k+ Q8 R* z                ar[i]=(int)(Math.random()*1000);
9 x, P# p, e4 U" B- o. Y' ^; H" Q! v+ T- ?
                }
; `- ~6 x3 v. y5 {) d- x$ M$ Q
7 T- [$ \0 z9 _0 N: U6 ]5 A" `        Arrays.sort(ar);4 r5 i$ k7 V- }: y# A+ U* a  t

3 E3 z$ Z3 L6 \                for(int i=0;i<n;i++)
7 ]+ J/ Z; c& e/ G$ k1 k
$ ?  Z8 c. Q& e1 [: N                {: y, m3 K# ~% e1 c/ l! p; }

& M9 ~: d* j' O4 L5 Q+ t) ]                System.out.print(ar[i]+"\n")        ; L' d) G7 O& t7 j4 ~

( D8 Z5 s. [# o, B                2 n& r# c7 u2 u. ?: L
+ K5 K% I! @. |% j/ p( x+ `) d- [
                }
  I1 m% p5 D7 g" Q& F& ^2 a- l+ e1 X) k! l. _8 y+ Q
        }# j3 t- M7 S/ [
5 C2 K  n# J0 J5 w
}
人平

TOP

返回列表