返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
1 N3 \5 W& N& y3 l2 t/ b+ }9 K) L
" t! k% h8 [8 T$ ^5 t7 w程式中可以輸入值9 l2 H: u5 m0 q3 @

# U: r3 |8 Z! L+ L+ f7 F# I實際寫出 jvd1038 G9 \6 p' A8 Q; r& l
9 [& f3 [& L( t5 j. f& c
使用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 資料函式引入; w7 E0 n( D5 Q# c/ T
9 h% l, d2 G8 Q7 f6 g% L0 ]* e2 r8 i
import java.util.Arrays ;
. j% R* O$ N) b' p1 a( c2 V# F; A! w6 Z

* u( _( S- {- b5 u0 b
1 u- Z! K6 U8 X5 l. wpublic class JVD103{
) v6 e. J6 \7 ~# k( w; S! m& ~
6 v/ i) a3 J/ n8 ~. t8 B7 ^: |4 {0 M; J6 |: C' ?

7 ]; b( c! Q$ e        public static void main(String arg[]){* o# p( }  j. Z; M

  {( y8 [9 o3 l% e. V, k, b0 X( L        
. O' U; B5 F1 P2 s
  E6 V' Q, X- _: c4 R        7 q9 n  @6 X( G% F% v# w' U$ s, m$ |

- @4 b: O7 w  }8 J                System.out.println("請輸入欲產生之亂數個數:");
% P8 Y' g. N% `6 ]
9 z# \: U0 C  J& X/ F        - [  R: j+ P( z1 z+ U: X2 P

' K* g4 k* }1 F9 L                int n = 0;  //輸入要產生亂數個數 並初始化* \. H. m# s) B
! i6 S9 b$ P( i5 q/ S3 `* |
                ! N0 y2 w  s' f

" w7 r& m0 Q+ \5 f                //使用到io 一定要加上 try catch. Z1 \( T- i5 H( Y3 _

  ]. B2 S+ `: Q) c/ m# C                try{: Z% [% i) b! @4 P4 m

) }. N6 ?, ~& ]& `3 j- X6 M* K                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流% V; {5 u- ?+ `4 v
3 t/ M# R$ G% a$ y# U- l
                        BufferedReader br = new BufferedReader(isr); //資料暫存區" f0 @" K4 W( F# ^, T- p% H$ f* y2 `

  U* l0 E1 f) s8 q( `0 U                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)% W/ f# j5 U- o* H

' W& n. W; O$ N6 v3 K, `                }catch(Exception e){}* A+ j7 P: }, _4 g+ ?$ r

; U- }* F8 y9 C               
1 n2 K: N: V9 ~  y% c
* w1 `& _, b5 D* z+ U. r                - @* c" h% Y# X4 Q8 A, m! u1 O

; k% W7 X" B! I# g! M, B, U7 o) \                int Num[] = new int[n];//產生n個亂數的變數
- k* w& w& t: Z# }- v' y* K1 R' S* M. J/ S/ g$ O
               
% [1 e5 i; m2 _% t- O( H% Q
, }3 C' w- s  w                for(int i=0;i<n;i++){. }" [0 ~$ ?9 v2 r( R* m/ V' X- c
' R$ @! i% A% C4 b6 s  E
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int); A+ D8 ^$ O! O; C# _
4 g' n8 |2 I, t
                        //System.out.println(Num[i]);+ z! Y1 y' B- K2 X+ `+ X
, E3 g* Y/ X% `6 i  s' B( D
                }
; K/ r& t' q6 }) H9 |; a- k* o
- x, H$ `( U8 p( i' w                Arrays.sort(Num); //排序
8 d: p& k& ~5 J+ |) U' x9 R4 k3 a# o; j2 Q& c  u6 w: U/ I
               
  g/ w4 ^# R8 C0 R; L7 W( L& z2 l, ^7 @+ j. T
                //輸出, `' H! _, X( z5 X# |+ H1 Z6 R6 U
* ~) Q/ E0 L8 x
                for(int i=0;i<n;i++){* ~. H) E  D7 o

6 Q; O+ S! w- U+ \4 v                   System.out.print(Num[i]+"\t");6 |3 t/ o. d/ e& z$ F: n1 I. q
. |9 `  v) l5 n" u
                }$ ~! V( x8 I; ~" s

+ L7 l4 I) E3 {1 d: c, ?, h) }                & s3 H. F% c9 d  Z
; F" {% j: U2 _
        }
2 A2 `8 o3 Q& w# \( p5 n5 I* q$ z+ K7 }6 B3 ~
6 L! a4 F' @6 @) @' ^
, }  {: X" m% k7 R' Y
}
人平

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;
( [7 B. I' P2 t3 L7 V7 Q7 {9 W7 O% p- d4 w2 I
import java.util.Scanner ;/ u. T, {6 K& J% Y" O

2 f4 D* J7 Q, w$ ]! T2 `public class j103
8 R" I% j, T8 T6 H
; G) t6 i6 m  F  h2 O1 ?& Y$ J{
- Q* O' r3 j) S! T9 C& \  o" W7 k' h8 b( ?3 s! `# M
        public static void main(String[]arg)
8 _- @3 g4 k1 K4 M, G2 i* k9 |' G* `% H9 P& u
        {/ f/ f9 n0 ~: `4 d+ s

0 I, b  r4 h' |* B3 \- P        System.out.println("請輸入欲產生之亂數個數");
, b& h/ y6 h8 |. N7 m% L  b" K7 O; l$ S4 L- b% E) I
        Scanner s=new Scanner(System.in);/ {+ J( }1 s) c+ l: @; B
% V) @0 m, h/ [6 j2 O5 F( ?/ c
        //System.out.println(s.nextInt());
4 B, x3 W" J3 G" @
1 t* e' [0 `3 y) n- d        int n = s.nextInt();0 p3 |6 I$ J: t+ ?2 ?5 q1 w

1 G' t6 K& D% H% }. s/ |! C        int ar[]=new int[n];. Q9 Z, {1 s$ ?+ M; q

( ~5 v9 V' X0 W; L. h& l' X                for(int i=0;i<n;i++)5 }; a) ?0 c9 o% I% z6 D9 B
8 l4 X- |" G5 f, g# f
                {
0 ~+ D' M0 K% {4 |5 j' v$ d1 l- [! f1 e0 m0 J& a8 I, P
                ar[i]=(int)(Math.random()*1000);
, B1 o3 L% s7 c9 L7 K
. U  X$ Q; |; I8 T+ v                }
5 K: o5 f+ j+ C7 Q; J- u3 I; Z* A' [8 f0 L% s; V
        Arrays.sort(ar);) {4 x$ b" t2 ~, b! N
2 H$ [+ c3 H  X9 u6 r$ u
                for(int i=0;i<n;i++)3 w3 N7 w8 R) a# j/ Z
' h" o; a* h2 _7 n+ R5 k. @: L6 \' k
                {
  C8 l0 U' X9 C% r% m
: q; P: S2 `8 v1 m, M1 Q1 G                System.out.print(ar[i]+"\n")        
# K% |$ D% F3 m; z
$ Y0 v: G# e/ U               
1 s2 u7 K' Q5 L4 ^1 g- }& O/ C2 e4 x4 v
                }4 @7 k% k" F! A' x; z3 v

) |, E1 n) s7 r" l8 S6 f: ?; a2 k        }
; O$ s# F& e7 A
1 t' y" T  x/ K}
人平

TOP

返回列表