返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
0 \/ b* @/ K0 [' _8 |
" p( c6 n" o  y) H程式中可以輸入值7 N# @* N* E* J3 w% G* T2 ]

( l2 o+ G: p  i& |1 ?0 a實際寫出 jvd103
/ u8 c6 f0 V: s# a
6 s% \! w8 N5 A使用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 資料函式引入
, @8 ]* G$ n* O$ I: i/ F! n. q
4 C) @) W! \. l# i0 gimport java.util.Arrays ;% j, E& [# \! ~

# x( M+ L/ o  C  }6 f; w& o5 Y, }* A$ H5 J$ S* Z
: P4 {4 V1 T& Q
public class JVD103{# D- \5 [5 d3 `4 A: u* U( X4 Q/ q# x" K

$ ?( j: u; I1 \. @' }* [% y: s& j2 q. f
/ _8 W/ X4 H  y7 h# s3 t6 C
        public static void main(String arg[]){
6 r3 x9 }! \% s* T
0 D1 D3 f4 g. [3 T: K% p' Q6 @          m/ W+ g+ ^. p) T8 m  Y
# [; N, {/ T" \* Z) W* M* a
        $ A0 R- m6 T6 m  V3 K' ]% t

4 E+ g" `/ ~* f. A/ ?  w                System.out.println("請輸入欲產生之亂數個數:");, m" W+ G* ^0 M/ m) e' _5 a6 z/ G

; p6 g5 |( c# f! _( n2 e  {# @        5 i; [$ P1 S# I% [) V& P& f
3 x* m! g5 U9 ~. X
                int n = 0;  //輸入要產生亂數個數 並初始化
/ v+ p. v" C8 e* [- V3 `% A5 P6 \" c3 E
               
; v8 {  }4 Q; G4 G7 v5 U5 j- p
9 q! J8 J- Y6 \                //使用到io 一定要加上 try catch
! O/ F# M2 R) \' r% J
& u5 I2 j+ q( I5 k* B                try{+ Q- i% x( z( p- d* J+ l; L
) [8 z: |! V9 y+ j
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
0 v0 [3 k! n" }1 [. w. I; o9 t1 O0 H4 U4 }/ e8 E& N
                        BufferedReader br = new BufferedReader(isr); //資料暫存區: ^& `, m7 z' J) {

& g$ T" Y% L  D% O5 c0 F+ I                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
4 p: a# N, o) c3 U7 l  A0 b. j- k9 P2 Y" }, I4 A
                }catch(Exception e){}; d) s0 L0 Z9 I6 j9 p5 @+ ^

8 h6 R# L+ l1 ^/ D2 I; [               
! B. e. ]8 p5 |7 S! |/ e( o5 s  g1 b. q" R. o$ Y
                + _4 U3 o9 x' g" S, T4 M. K' o

* d4 M1 H" @1 N& A$ R                int Num[] = new int[n];//產生n個亂數的變數
8 R3 L! h$ X6 {& ?; S+ S' t+ l( q2 Q  U* t# i5 b/ a
               
" T0 y5 f! J1 i, v, D
; w! l" R( f" E, _; v                for(int i=0;i<n;i++){$ \" s2 a1 E" g; f& M0 T" k! k

- B) x. c  v+ V                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
$ t0 I. b' y) H! l, l$ w6 q  j# q( h: w
                        //System.out.println(Num[i]);
8 m, p' u9 N9 U7 v2 g6 w2 q' ?/ H7 c$ O3 Y# ]6 ?
                }. a& M+ c6 G# ?- i; P( Q

7 o5 Y, e5 R$ }5 e6 B+ e' d                Arrays.sort(Num); //排序
$ D. n& i. b  d# g3 Z  b8 j1 v
' m" b4 n3 c% N/ w* ?$ U) c               
: n) |7 Y7 N6 F1 c( W+ x% R
. Y7 f+ T! C% x                //輸出
+ W  t/ S* i  L" s0 k$ Y: i3 X1 G# m9 l. q* M+ k
                for(int i=0;i<n;i++){
/ {: L, Y9 x8 j1 P
* B4 I9 m7 i! S                   System.out.print(Num[i]+"\t");
, r2 R( I$ `) l- n, Y; l, J6 ~  t" M# f% M( h0 U7 L
                }; [0 C2 Z0 C5 T0 H+ j  [8 @

' V$ z  }$ S* i) T1 `2 ?2 C/ x               
- c+ m4 P) ?/ O: Z% b" \2 i+ [7 b$ e
2 ?' o2 t$ A" a5 I        }
2 O) h5 E; ]# I" \+ Q6 d4 o5 l, p
9 y$ e! m; \" B6 i. y5 ]8 f8 ?, R, R- u5 u0 L

% U/ A) B2 g( ?6 `; b% E5 U}
人平

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;9 h2 H# i* G+ u4 F5 R

& p: Q- H/ f; q2 B8 Simport java.util.Scanner ;
9 W. x/ X# |( {) ~  m( L4 O" C/ U
2 |) V' l2 ^( {public class j103
  u5 E& X- f- P
6 R3 p: |2 s" }; T! E: m{
( r- J) O9 b6 i9 \( r
6 n) T. `6 _7 W. [" D) O8 ^        public static void main(String[]arg)6 e- r7 k  S3 \% V

) o0 B0 L# p+ G; R# q/ {        {" ]- O" M, k$ t& u* A7 I( t& U
# [- _- o7 a! P; C( j4 R- ?8 c
        System.out.println("請輸入欲產生之亂數個數");
/ A+ q9 u' l- e/ G3 @* |  m9 @1 n9 @: W
        Scanner s=new Scanner(System.in);2 @9 a3 `, i. v9 w- k

* p% o5 l+ g* r7 A) Z/ _' I* k! g: I        //System.out.println(s.nextInt());
+ }: H3 X' V6 @) W
  j$ s) x8 i, F" Y; {        int n = s.nextInt();
9 w3 n3 U: b4 e* L  b- h5 {0 a
" C: R, l8 C& g* o6 k/ }9 Q        int ar[]=new int[n];( D8 h* Z# [8 x$ Z9 a/ E
% p: L. o# h6 c2 r
                for(int i=0;i<n;i++)  B7 u0 A2 n% H6 Q; I! H
0 M9 V/ w4 M, Y9 G
                {6 B# ~* L3 F9 \3 |

1 n1 B4 {& {6 T2 W                ar[i]=(int)(Math.random()*1000);2 V) U% s1 ]3 z9 C( P' L2 J
8 y0 x; S, w. n& d9 i5 {
                }
) `' i) G& \+ `, F
& N! r# \3 z8 m/ e% o* F        Arrays.sort(ar);4 A0 V) g+ u9 ^0 G7 `+ @! t1 M# h
: n3 L! P9 g9 L. n1 ~; a/ x6 v! Q) J
                for(int i=0;i<n;i++)' \. @: }( D" ~. V5 y# d3 {  _

: ]5 ^. t- p6 s. d" ]# m' Z) t                {/ e/ f" P- S" X6 k1 U& c$ c2 K

, Z9 U  o7 ?, N4 r0 y1 E  v                System.out.print(ar[i]+"\n")        ' i7 a& J7 W' Q" \- Q5 U6 ]. S

; m# Q# y% s8 n. V/ ^3 W                # C2 W- [! j* q4 [

- w$ D7 k+ N" g8 X5 @6 Q) }. @" t: c                }
1 G" `' R7 t8 [" {: g& _- f
' b. {6 l) C9 w: B6 v0 H2 d% s/ ]        }& X$ {3 c# G" _+ ?( r
6 v, ]6 }2 }1 R7 e9 j# {( ]1 l. `
}
人平

TOP

返回列表