返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
# }3 I% E9 S/ ]4 A
+ F) A6 a( D2 B" L9 R程式中可以輸入值9 @5 v; M' R0 C5 f' \. J
4 ?: U( W, U# \) `# U
實際寫出 jvd103( S, F) q8 `5 f3 b) A

- @" Z! ?  d" }$ r0 z+ b* x( |* j' M& C5 h使用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 資料函式引入
! [3 T5 O! Z) N' p2 |, O9 _6 A/ z! i
5 g9 O! B3 q, s, bimport java.util.Arrays ;1 [6 s' Y7 }+ ^* w5 b* V, A

6 w5 q6 `7 L0 H" p/ a7 d. q* C* s0 E

6 c6 T" E6 z3 \+ M' z  {public class JVD103{# I5 i% H5 W* X9 k( r

* @/ v) h% J+ ?( _
* e' O0 T' E( E, U2 q/ ]& h, p' @: `, w, W
        public static void main(String arg[]){. N4 i1 V- n+ z! Z

+ b/ `& O5 f3 G* Y5 c$ P        
' L  l7 B7 o4 t  A; F' }: O' T, |) l: z& c
        0 R7 [8 f: P8 r0 z$ ^
( P3 D- r5 b5 b8 R# t
                System.out.println("請輸入欲產生之亂數個數:");
# {( y* r6 [# M# b( |$ |
& v  k( X! l" q; S$ G        
$ T, g/ t/ \% I
) m" K) X% s2 I9 R+ A1 d/ {                int n = 0;  //輸入要產生亂數個數 並初始化$ P9 ~2 |$ r9 D. a: A3 T
8 f* _0 r1 h8 N
                5 h& j; @4 q/ y2 M7 g

8 @7 c: F; E5 ^& P8 }                //使用到io 一定要加上 try catch
. a* T2 n# u6 O8 k0 t5 h  I, U) r; W) t
                try{
3 q& v: ?: C- V% W# d7 N/ \, D* W( D2 A! ]
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
& J( t. L/ ?! ]- {) P" B; }0 {7 J0 q
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
4 {' Z$ _  ]6 w9 [7 N% Q* q* l* I. p" U$ b" H4 a
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
4 D; P5 F8 z: w/ B
7 G7 X) S1 Y* Y$ `) t3 U, m                }catch(Exception e){}
  T7 L2 ]$ h+ {6 N7 e: d" v* G! u: Q
7 a' C  G0 E; w4 q                - W! b% c# a6 s+ E6 A
4 Q- s# ~5 u3 k- b
                9 x$ V0 z+ p8 @7 S! Q& d( I, Y

' Z, O9 `7 F! C# {8 Q9 @                int Num[] = new int[n];//產生n個亂數的變數  ?8 Q( G; B$ j/ D

! u4 H6 p2 v1 r, _               
( v7 P, s' D' d& y$ K; ?8 B$ ?: D$ L0 E) n. `8 ?) @
                for(int i=0;i<n;i++){: p8 U  f; t' W$ F# J5 L, [

1 Y4 P" z1 [. C! D& [                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int): z& v& S' V4 ]5 T- m
& W* w2 ]. `7 ^( V1 r0 |% C
                        //System.out.println(Num[i]);" A9 n$ R! Y3 A& l9 y5 _% ?
1 ]/ D3 y  x8 r! d1 u, Z4 `
                }' e( G# d' K' c. P8 |' P

. _* [4 u4 w9 G9 p- m                Arrays.sort(Num); //排序
3 B3 ]4 _9 Y# R& A- [' R0 f5 P9 L  H0 }, s0 j% F" ^
               
( P$ G- T6 C$ r2 y4 u/ _7 O% X! a& V. B5 K' C* ]/ [+ ^. y
                //輸出
! @* I9 \! Q- Q6 K: r8 v5 @
) g# @1 f& Q) e/ k* S4 y                for(int i=0;i<n;i++){# i; V1 ^; R  |9 S+ I
9 q& U+ g1 r& U; I9 R. Q
                   System.out.print(Num[i]+"\t");
/ L) a4 N" S; B
! {  y( {  f( ]! K- k6 c                }
& s3 f; a7 `0 V  {
+ q. ]. B" d; R* L, L9 D- d- D               
- ~/ j: h" _/ q: o5 o# o% @+ m9 w6 r
        }5 n& I6 x% J: t% J5 U7 Z

, I1 l; [: ]: e7 l3 q5 G; D! M+ I) [4 }$ Z

+ A7 Z3 U) W$ K4 s6 k! d2 Q}
人平

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;
$ i7 F/ t$ ?+ J7 p
5 A1 Z4 l$ c% Q+ K0 q2 T7 W) eimport java.util.Scanner ;
! A. x9 q; D9 M+ F1 g: H7 M; a* Z
+ \, A/ t( {- L& upublic class j103
) _9 k4 ]1 f& d0 I3 l! e
% X3 Z* n; H( b, ]6 a{3 ]' ?* S0 C/ G7 \8 ~
- Q# ?( U& {* w' x' v( s
        public static void main(String[]arg)! Z0 c8 M( j5 P+ U9 s
7 y; W$ S* H' _) o8 P' f
        {! Q& R/ n( \; H! i
6 O2 @/ E2 {% j
        System.out.println("請輸入欲產生之亂數個數");
8 k9 P: [  ?; S( H0 d4 {
" R* Q, o7 z" N- I) R; M# F        Scanner s=new Scanner(System.in);
/ ?+ `5 w) o/ J) T1 A2 C' [3 }4 R. r4 v; @, M. c; Y$ r
        //System.out.println(s.nextInt());
/ _. a9 V) X& u; G8 B/ M
9 Q: M" O0 s. n; V( M3 F, j0 O        int n = s.nextInt();3 s- p3 y3 A# s  v: G! z

" d4 V; p  l! o+ i' c( I! ~. u, u        int ar[]=new int[n];3 }' n4 q4 ?- g
) Q! C* z6 X/ d% A, M: u
                for(int i=0;i<n;i++)
  c& \; w( F4 r% u& w( v8 G, B* s4 A  B" w1 E$ H! S, l
                {
3 K& j/ O+ M/ ]6 W* G- A% A! y% p  f% H! k0 u& N, f$ f) i
                ar[i]=(int)(Math.random()*1000);8 w& |2 c1 n6 I, ^
: x" _) n2 A3 h& B8 ?
                }$ }$ f# _8 _# P, z5 A7 P

: [& M2 ^9 f3 p, }5 |. P& z: P5 s8 L        Arrays.sort(ar);! P, c5 C4 p) T

, l2 B6 }3 X8 X/ Y5 h3 u: ~. M( u                for(int i=0;i<n;i++)
5 C; o- x4 s% l2 H
( J2 K" ^$ T4 |% e; L' P0 K  w3 {                {
3 y4 {) Q5 v6 z) H# Q! L
( r9 g6 |6 H4 e2 e                System.out.print(ar[i]+"\n")        
$ R7 u% Y. \3 ]& [( Q7 E0 w& [: n. r+ @. Y7 X5 s
               
" |/ c1 P! C4 m' ?% W8 u* a4 l; p6 F* y8 B; f0 q8 e+ m" M
                }
; \, H1 s" E! j: R% `8 f) x1 w' d3 n1 q8 [0 C  c- c
        }
9 @5 z! c* `; p. Y' q( |" Z: ~9 k3 v7 n
}
人平

TOP

返回列表