返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 0 L3 {; D# c6 d/ a
! {' n) X1 N0 A+ H, J
程式中可以輸入值5 R1 e' ^' ?/ I# ?6 z; C

( P6 E8 F/ a% @" V  ]8 Z實際寫出 jvd103) `, }- E  _' ?' ^0 _1 l6 A. a6 A
- w0 N' u$ i% n% l/ n" j
使用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 資料函式引入$ {* {; M$ }: \3 x, u: x  m2 K

6 @; |; ]- D! n0 o  t3 rimport java.util.Arrays ;' k5 |% r# C5 n0 [& O
: c$ W" m4 M- j# i1 D. f0 \; K

, D$ Y8 s( {3 c) l  m! s5 w  Z, X! z1 n( X+ @
public class JVD103{
! Y& h1 U5 N2 D) B# V! Z! ^' Z3 U: p: B

- e3 z7 A& c4 v+ h$ N) \( f+ Z; m/ k( N& t4 d. U9 [
        public static void main(String arg[]){
$ h+ ?$ w& |* e4 r# s* ?
& V. O/ E! b7 Q. L        7 z8 K( F3 u( w7 r! v. R

: M* R" J  a- [) b+ Y        
) H" t( p0 p7 o+ ^& E- z/ A7 C
8 b% F9 n, E8 H7 V                System.out.println("請輸入欲產生之亂數個數:");6 u9 j0 p! O9 E" G9 Q+ o& R0 [
. v, T! y8 C3 V5 e* N( I1 y
        
. r  b- g9 z0 Q' B
0 n; A# o  _' E9 N                int n = 0;  //輸入要產生亂數個數 並初始化: n/ f0 S8 Y' o) w

( ~  W2 a! }6 d$ m                : w. {$ ^$ t$ W, n
6 C5 e8 h& u# e! X/ r% u; ?# ]
                //使用到io 一定要加上 try catch/ E' {& s$ P6 n+ p4 P' P! h9 O+ l
' ]" P1 K: o) a: h( w) {- z
                try{& X  z- Z0 q' {/ p

  }& j  V" N+ H: y. J5 P1 D                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流. p6 f  Y+ ]3 C- z
" G8 S2 j* q* A: ~& S
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
( |3 |+ R, v. J) Z' f
: r( @) ]( U( V' R/ U, J1 K* K                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)" k$ k, H! R  m& o# |  F

  i5 y# B( x8 u# d* J                }catch(Exception e){}
/ a. _, V3 s, `: T( W& t" K7 y& k7 H' y9 \
                / d0 L6 \- q7 e# @; e/ g& n
: r( x$ D! ?" ^, c) N% }
                , E% Y- [$ i$ s0 w7 X7 @$ {
' `- ]) y5 D! y' p9 [
                int Num[] = new int[n];//產生n個亂數的變數* Y& u8 d, S% J5 x  T! j3 \5 u8 u

/ N% `3 r- u! }  S0 T               
; R, h' b7 U: X* R
& v3 y  l% `! c& q: d3 z1 l                for(int i=0;i<n;i++){
! M" D7 h; K( V0 U1 P* T
+ y& [  }' w: u7 [                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
  e8 R' z6 W0 N$ m+ `2 D8 I7 Z, t6 p8 f+ ~3 x
                        //System.out.println(Num[i]);
4 J& m6 u+ u! }3 R$ k" `1 T" K3 N8 Q3 Y( U6 B( E& J
                }
% e1 a; V5 Z: E) e/ F4 U( W3 O' A4 }
                Arrays.sort(Num); //排序
9 h( e. X+ c3 c- {; p
8 d: ]. J2 p* _6 ?6 o3 ]                : ^+ ]4 R( k+ _3 v! k/ ?7 U

- u: L0 h" V# W, y; ?/ `* B4 _  \                //輸出- p' v1 k# |4 E6 R7 V

) k, s% f* |5 y2 r! a                for(int i=0;i<n;i++){
5 C+ z) n8 c6 _, i6 f# _" t! M" Y& U. p2 w/ _
                   System.out.print(Num[i]+"\t");
0 X5 k5 g1 s( r* ?0 }( g
2 v$ D* \" V! {' o6 g                }# D7 ?) K, r2 @% u: H5 m- _) \  e

8 W' M% y: E$ T1 N                9 j, a& e2 S) q8 ]
9 ?5 S: Q' p7 A) ]! u7 f
        }9 H$ i" _- |" U- z+ b' S2 p6 Z

# M% v1 v5 H! U) G6 g# H/ t( J% K0 F4 L) y

+ E" Y; u# J4 I/ z}
人平

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;4 L* K: H5 U" S: W+ B! e3 P' N  C

8 ^# A( g) O$ p5 W) simport java.util.Scanner ;
+ G# p2 F. S2 _& \: K  ~/ J/ D% y( P7 L& \
public class j103
/ K( k$ k# M3 k1 s# w8 Y3 a5 I2 f
{! y4 [3 N. S2 t, @6 a, `

3 ~$ I- M; e/ C9 e9 M        public static void main(String[]arg)8 ~; p6 _$ U4 z  {) C, \0 l5 Q
* f* o( X: w$ D9 Q) ]5 v# c
        {' \# H% a2 d7 H% ^# X" N9 O
0 V' r3 y6 u' C- S: S
        System.out.println("請輸入欲產生之亂數個數");
3 e  @# }9 Q& Z$ w3 m: n- k7 ]% D! u1 H) O
        Scanner s=new Scanner(System.in);
: N3 j% l) ]0 g: H4 ]9 L& h; Y8 f$ @% x6 I
        //System.out.println(s.nextInt());7 j- `2 z7 I" x

/ [+ J: {5 r) I        int n = s.nextInt();
& x' B  U% E6 w; L/ O! n: g
8 R: T6 N& t* Y/ Q5 y  H- i        int ar[]=new int[n];' J5 q! f% w; {5 A; l$ o0 Z8 E
8 y& B6 n" S0 y
                for(int i=0;i<n;i++)( E2 o5 d' [8 f3 i+ c
: d: D, P2 X3 j% h. Z) B5 J
                {) X" m8 Z) @5 c. ?

6 \) k$ j% i' F' [* o0 q                ar[i]=(int)(Math.random()*1000);
9 [" u+ W- G0 [0 I$ t/ n) x
, i/ \3 Z8 F* B% V                }* v3 N  f+ V" Z* a$ ^, c/ Q

7 j( a/ M- e9 E9 m        Arrays.sort(ar);7 x9 u7 r! {9 B! y0 g- D9 k% G
2 G# z+ E! Y2 t( |- \9 w1 }
                for(int i=0;i<n;i++)
5 d  q$ H$ C" U. P3 e) J, k
3 }0 o, M8 b: j$ S8 i                {
' i' c* w% I- `9 c! v5 k2 E! _
* a  U7 s4 a- r                System.out.print(ar[i]+"\n")        . l& Q  p4 P% J0 k

7 _/ ]; S2 c7 w6 v" O7 m, R               
0 ]- _! ~- C( e1 M' X
+ n. r9 i" O6 {: ?2 ^                }
, W/ t8 o' d6 g# n, p* `9 T) j7 V, Q
2 z& T. |7 E5 V$ f/ b: j        }
; ^& a5 c- R( o* v
0 w, C% A' h/ v4 V}
人平

TOP

返回列表