返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 6 J2 ?1 A) p# P: g1 I

+ r! X% |% C- G2 C3 u3 A, `程式中可以輸入值8 ?* X" r3 t6 G6 A+ J
0 S0 ?8 @# `3 N1 ^/ o# A
實際寫出 jvd103& ?/ D9 O# p% N( I2 u* E
( h/ Z% |) O" W0 p9 F0 S
使用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 資料函式引入
% U' J  [! @, n, S6 U$ p1 x( S
import java.util.Arrays ;
4 ]; a* ]( N* ]9 h! `% q( z( i
) c# g. j' L& J# J2 M. P( }) M  d+ W7 v9 H% ?

& K" S- _2 x* x7 Hpublic class JVD103{$ B# M9 V( Q+ v2 E+ F) n
( }0 e- n; G! A: o+ v5 M
) a8 v# S. t0 t  Y

8 X5 a7 y9 \6 L7 e$ P        public static void main(String arg[]){
0 S' E8 }+ x2 O! x$ c
& f- W2 C3 u( v0 O$ D. J: _        $ h( z. t- K4 p, Y% d7 X$ `

0 z1 x" J3 q" M+ Q$ R4 b/ O        8 Y% N) ~6 U) W( f& T2 D
3 t3 I* Z  W9 t% S1 v% d# O/ [0 k
                System.out.println("請輸入欲產生之亂數個數:");' Y9 w# a+ a; D& Y4 h& r# w0 N

- l* J8 ]. r! ?) u9 i* n        & |; v6 L* C9 O9 g0 ~

5 ?) A9 L) D/ y7 J; H; l7 @  g                int n = 0;  //輸入要產生亂數個數 並初始化$ b+ {9 @- I) W& r' s3 g
  n+ p' u9 ?, M% T8 }
                ) @; ^. r, S! T2 [+ D

4 h/ L: s4 U3 C. u! j9 d6 R+ ?                //使用到io 一定要加上 try catch
8 v0 D/ P5 J% `! R* R4 W/ v  D- }+ I! g
                try{* y7 S; K1 f+ F$ G' J

4 O8 L9 g3 _- f# c% J$ P                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流% t5 w4 |7 @6 t* v
5 n4 g' Q5 g9 T; \1 k: F2 }/ C" g6 w
                        BufferedReader br = new BufferedReader(isr); //資料暫存區% B4 b, q$ o* z& _& b: `0 Y" i

: N: f3 Z3 N; f9 r9 s                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
1 n1 Q3 L  v3 k3 T2 P/ q- ^
1 N8 D) T9 g6 x) J* }9 ]3 O                }catch(Exception e){}- e# |1 Y5 |( ?0 ~% A

2 Y! v7 y0 U; E0 q                1 h0 ?1 I3 X* v  z* L+ }5 M8 {3 v

, s$ t! k' P6 O$ `1 y                ; o8 i) d0 G3 }, O# c

, f/ ]' K3 r. ^/ `                int Num[] = new int[n];//產生n個亂數的變數9 t- @6 G, J6 c2 t# M8 U
& y* _3 N% R! l  x
               
6 u  {8 R9 y. c$ ]/ V2 t
( f; J3 x; S# w9 d                for(int i=0;i<n;i++){
# A6 ]9 F3 G! z( [% e( S0 z( n1 F& \7 ~! W: @# X; e, F$ c8 J& u
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
& S% ?' b1 {7 v; y. x/ r( Y7 i% {1 b; h- N+ o3 e
                        //System.out.println(Num[i]);: d: K; ]" X6 v; [6 U5 M. H
# A: D/ p, A7 @1 p
                }
" C  D/ ?& T, r( J( x
. [9 j7 R+ ~+ c% z% b+ p                Arrays.sort(Num); //排序
1 I# J! G" Y! k% p/ _# h; i, D) b! E
) T( b) e( r" F6 C# R" ^8 F                ! B0 A' o# W% h1 {+ b

1 m5 D8 _% k! P% G* K; }/ O* M                //輸出8 W$ J% m& E1 P& s$ `8 g, P

9 i& A- B) d# }% S0 r  E% i                for(int i=0;i<n;i++){
" L: b6 u% ^) i. L' O% @3 P( I( `  Y9 L# K. {& T
                   System.out.print(Num[i]+"\t");
, g+ R( p) Y3 B; k+ j7 b. e6 o
5 ?& q2 A* w- i! Y& z$ f; ]                }' R$ Y0 F1 N6 @9 o" j; t

* e9 ~8 P$ b) A+ B6 t3 M               
6 z# N% i7 P: a0 c+ ^! J9 P/ v9 |- k; _7 u% i! u
        }
) F2 j) W& n  e& O4 O
" J- I  H+ }+ `! ]
' M' _5 Q% @/ t9 e7 {
8 o: T# p: v# A* }% ?}
人平

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;. F: w2 ]6 X4 Q3 F6 G; J0 @; c0 j" D

% d$ V( R5 ]4 n$ L8 W' simport java.util.Scanner ;
# u, h. C2 Q8 c7 D
" A* Z; z' r. q9 F( e' y( J  Xpublic class j103; u7 o  j7 x8 b5 @/ w7 q$ S

. {7 R5 L  t6 @) P$ J{9 O" h, r9 |9 ~2 F- v

0 I4 j) b! j* H, B4 [1 o& D  c6 w        public static void main(String[]arg)0 Q3 e: U5 L& e% f1 X. z+ V6 f9 R
- h% E' o2 M) }9 p/ g& \- c6 T2 _0 }+ w
        {2 r( N3 g3 Y5 ], m& J+ W. E+ m" W
; Q) H- _; }. p+ r0 P3 K. }
        System.out.println("請輸入欲產生之亂數個數");
2 x' j( [, o, ~  P- Y# L+ p2 U! F2 e& J9 M' R9 u( o! Z
        Scanner s=new Scanner(System.in);: r; ]  ?6 q+ c3 [

. j' r0 d& D/ H. D7 W        //System.out.println(s.nextInt());/ I4 `( ~% \! w5 O9 ?4 u4 L, P  ]

& d1 H8 a2 n/ k4 s) I( M6 C        int n = s.nextInt();! B, w9 c  H# f" O
1 A: T7 a; @3 l% n9 z9 X# t$ h
        int ar[]=new int[n];
( s, M5 s! E$ a8 v. S9 g% i# ?+ n* G
                for(int i=0;i<n;i++)3 r0 F  B, O. i- J% ~: \* H

& v6 _6 _; W) c: K' ?% q1 i                {
6 T  ~0 \( l' c; R0 Y/ k  ~7 j7 m. l' \1 Q! D# s& V& D" b
                ar[i]=(int)(Math.random()*1000);; A# R, g( p; _. r. I9 f

8 w2 `4 `% |2 @# O4 C, _) _5 z; b                }
# w  d5 X  E# @7 {0 K" O
0 M& Y/ E9 U) z8 ^        Arrays.sort(ar);
* V. G  a1 G3 @" `4 l
7 W, W4 l# q# `) p7 p                for(int i=0;i<n;i++)
& o6 E/ j/ B. p5 w  o/ t1 r  l% N9 o5 W- x# g8 n3 I
                {3 y- t4 z' Y+ N
/ t8 X! W0 D) c8 z$ J
                System.out.print(ar[i]+"\n")        
4 y1 Y: z3 o9 s' U. c( U6 X# z/ n
                : d& B5 l# K, c

$ T1 @5 v. g+ m% l/ Q* k                }7 o4 A. z& ^/ d

) v" a2 `! W# x$ }        }4 V4 s- `5 v8 U7 ~$ S+ e, y9 @' }( j

) J/ G) F3 D3 d! _( k. O0 q& [3 i3 w}
人平

TOP

返回列表