返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
9 V( I* o: ~9 X+ {* j  [
- E( k  T4 O2 n! N; j$ i程式中可以輸入值
9 G2 J* T& f# z0 ]
5 n8 A% \; Q3 _0 A* z9 y8 L0 Z0 v實際寫出 jvd103
, w' i! O" O! _, L/ o1 Y  E
9 u" s# `  q6 g. W& C6 ]使用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 資料函式引入) n/ L% v' I- l. M; C

/ y3 G# A+ p; f2 I, C! d+ ximport java.util.Arrays ;
9 e4 A, ?$ G0 F& C. d
- a& b( g9 S+ K5 o) L
  n1 g6 `' i2 m2 t. F# w$ q# N& T' U* F( e/ j" D# m
public class JVD103{3 `4 l  B6 f% r2 s+ g: u

' P6 B- U. t9 j  Q0 x$ M
; U4 z0 d, U2 c$ t' R5 w; j& `- y$ `0 p8 k
        public static void main(String arg[]){/ F9 F& x) H4 J6 |* J
: t' A3 }8 ]* y5 k, w
        
" h4 P5 ?7 Z3 j! b# s+ ?* F$ S# X: S3 M& e1 ]& w
        
8 |; z7 k9 v2 J3 p. N0 t$ T8 k! I& y
                System.out.println("請輸入欲產生之亂數個數:");" Q1 X) e# g: e) U" a# n) E8 T
7 ]( e' c$ w! N+ p" x# E: U
        8 X( q3 d4 C4 k: w% R, f& J8 C/ o$ G

+ G! U/ U- c* t                int n = 0;  //輸入要產生亂數個數 並初始化
$ H  Z+ ~( X) x/ `; O% C7 n5 r# H- J8 A  K
                / B1 a& H; ~6 m1 n

1 t/ w. n$ A& k3 H                //使用到io 一定要加上 try catch" O$ a6 v# D7 m

& B$ i- t/ |6 ?( D                try{* M/ T& n6 A# g. q

) O0 B; o1 f" S# \                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流. J8 G$ k% Q/ G

2 e; ~: c3 O4 }! c6 u, x                        BufferedReader br = new BufferedReader(isr); //資料暫存區5 X/ L; `4 u5 d

6 N* u! O  E4 J! Q( e                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)6 v7 _: [5 {3 l  F! y( f' H

7 ]+ i; D. e6 N6 ?( d                }catch(Exception e){}
: A2 h( |4 @1 g8 V
; t8 C/ Z8 n- H% p1 q                5 m& M$ e7 \/ A. j- Y; T

! v" {- c6 A3 t                : B( U9 ]' P% ]
# f, X+ d6 `/ T; d9 r8 j; q
                int Num[] = new int[n];//產生n個亂數的變數0 x1 y4 ~/ R9 p6 B
+ W# @. Z2 t, G! ^) B
                ' U) T( s& T. r' c
9 U+ r; }3 Y# d' b+ J' m$ Z, ^
                for(int i=0;i<n;i++){
9 A% n1 D) @$ P& t9 e& f! k/ h/ `8 ?9 G
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)0 Y0 o# b( o. M% `5 h( U5 f
* D2 x' s7 w# v* U4 Y
                        //System.out.println(Num[i]);
6 K7 R9 G  m+ E! s+ `( t0 i
3 `0 @# P+ e. x1 g: J9 c                }
# b8 R' E  H: v$ T8 @* J2 |0 J0 J
, Q  p8 m0 Q) W, F4 f                Arrays.sort(Num); //排序- [. {" O- S0 }" O
- j/ B" i! w+ k; l) U
               
" }& k% {! a5 S; o. w/ l# P1 R5 J# Z; P  N( X' N% Q
                //輸出
# P% r  u4 Z1 ?4 r" O% L- f: L. Q/ Z+ d. b
                for(int i=0;i<n;i++){
5 ?2 ?) k$ T, t& [& J) {$ S: F1 x% O  i! E. c4 [8 w, ?  ^( f
                   System.out.print(Num[i]+"\t");6 }+ R! B5 ^7 W* N
0 r6 ^# o& c2 o6 l$ A) u1 d! G8 u
                }
* L6 O7 W- A; R0 m4 @: c& M
8 j2 K% j+ U1 F; [. Q4 L; u                : d- s7 ?# H  Y7 O
. p* V" v/ x% b- d# c% D
        }
1 }; U& S8 @3 e. a$ y0 d0 A
8 l% c3 r! N" U2 J4 T( i+ F: E

. ~. S" _% ~; E" ~1 g}
人平

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;
3 J* i7 d0 X& N2 l0 S
0 a! {* K# W4 W! X3 [import java.util.Scanner ;- B$ R) q7 ~2 b5 Z; c( g5 o8 z; O5 L

0 L* V: [- i7 k. q0 }public class j103
1 W* A3 [% n4 u% A6 L" `* \' w( r0 g% u0 x% w
{
9 Y2 A- Y  k9 L' ?, f1 \! X7 F  @; b
        public static void main(String[]arg)% z3 @; d2 q6 x
. T3 ^, t& \! E& F$ g) l* [# ?
        {+ w' ?" z' d; u7 u
+ l! ^+ X" K6 A/ c2 K3 Y
        System.out.println("請輸入欲產生之亂數個數");
1 y% L' s8 k/ ]; V# h# a1 m3 A/ i% f9 q! I3 I7 z
        Scanner s=new Scanner(System.in);9 V+ E# b# v! T  K: M1 F

4 p8 i: K( b) f. g  |1 B" _1 p% r        //System.out.println(s.nextInt());
' m9 ~5 _8 @. m0 M# }; n' x% W% X$ G
        int n = s.nextInt();! v9 y1 G, q# `( O4 k
- d. u: D9 P  P
        int ar[]=new int[n];
& s, P1 _1 i4 s5 t' Q" k; [% ~+ X% r6 U# W' c' q8 `% m
                for(int i=0;i<n;i++)& [( r7 e7 r$ N1 Z7 q3 r' x

5 E3 R5 k, T5 @& A8 ^                {$ @8 K3 b. X# o

' B' }9 A0 `; m                ar[i]=(int)(Math.random()*1000);8 q$ |3 j; O. T* F- a+ a$ A
; o- w: q: }/ l0 F* V) ?/ D' `
                }
4 v; _  @: q3 t% ?. Z3 O" M
: e( D* {! Q$ P3 g        Arrays.sort(ar);: _5 Q3 N. x2 d
) A( g% b. M( h' K9 o" h+ `
                for(int i=0;i<n;i++)
4 S# G( e% P/ x% k' [& j$ Y6 Z
1 C4 o1 K$ W" b& E! ]5 |                {; C7 Y' m) k  G2 c* q% h5 L
% |6 W6 d5 G* a' S: d- \
                System.out.print(ar[i]+"\n")        $ H. C3 _' o! W  f$ |0 t7 s1 d% r, B

; I  S+ `6 a) f; l7 f: ?                3 [- C; z8 a/ k8 O( M2 t) B
+ I, s4 m2 ?" |6 ^& o
                }5 _1 O6 \5 i8 _) M
; y! g( P8 u( u* O
        }7 [- `) ^3 O( d7 o% f9 ]

" _) l# {4 ]! @. d) s  C}
人平

TOP

返回列表