返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
  y& p0 L2 H5 U8 ^3 Q) P" `  ]: {& e+ Q2 D
程式中可以輸入值
1 c0 t6 P. S! c: d1 g+ A! Z# W! l# E6 s* {
實際寫出 jvd103
5 ^' H3 I* }3 a7 d2 W# m# |( y; u3 J' C- C5 i
使用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.util.Arrays;$ R/ f) e! A3 Y" ~0 a5 R

  h* y2 L3 |* W: ^' C+ limport java.util.Scanner ;
7 G0 H7 _+ c( a! \7 W
& T& @& z; \% s8 xpublic class j1032 D8 o$ r! P# |5 {, |

/ M* R5 ~$ m' A. J& M+ E{" U2 L0 c4 j+ S: x$ Z

8 e. H) |3 p% }8 Q! D        public static void main(String[]arg)& B) R  Q  |7 a) `7 G4 E0 ?& V
  N% H( N# w' A8 Q0 a. _
        {8 `5 W' a3 @( D" H! `1 G

* J' b& N; U* [0 J7 g& m, D        System.out.println("請輸入欲產生之亂數個數");; S! ~4 o  }2 A' L% ~3 q

4 u6 N3 U6 R$ I! b" r+ j3 x        Scanner s=new Scanner(System.in);
1 ]8 C: Z4 Q* P) [' s/ R3 P4 Z; O* A; X
        //System.out.println(s.nextInt());
4 h: [8 S% o# u4 `* z2 w- h) t! t0 m7 r: T
        int n = s.nextInt();
# a% x4 j# h$ ]/ t. e, o/ d9 v* G; c2 v6 I6 H' {7 Q% Q  Y! \% i
        int ar[]=new int[n];
+ q3 Y* A# ]3 h3 E( p
" K; U# E8 [/ V( S) s7 o                for(int i=0;i<n;i++)
- s  t' C+ s6 y) D1 x4 j" p
" d& b8 n& y8 J( g                {' g% x7 I/ V' K0 P4 z. M* p- L
' u* o7 t* x, }- O( c
                ar[i]=(int)(Math.random()*1000);8 |3 \- c: {6 _/ G) k" u  c
: |) s" |- M8 N2 d
                }1 E9 e6 _5 }: t' E, @; w5 B- V
0 P* X; e8 M8 w6 k
        Arrays.sort(ar);2 o( O! Z& T' K$ l7 D
; C+ R7 ^+ i- r2 h5 m$ f* k
                for(int i=0;i<n;i++)
' M9 {) R; `& m: |/ N* F/ h( c% T+ r
                {
! `/ V  R+ i; x) A: D" p/ Z  R
) R) J9 {/ D; N3 S# V  u, b, p1 Z                System.out.print(ar[i]+"\n")        . G/ s# e5 u/ v4 L, A

* X& i7 P* l% d% o. }" g               
/ }7 _4 w7 J9 [# Q; c& g& H. ~
                }5 e5 m+ Q, |8 I' }4 v$ j4 ^' Y
# j& h) `! C! }  |5 Z+ `2 D2 V
        }
0 n+ y8 N9 F1 T- t/ D" h
; z: V, E* Y* J) ^; W% |}
人平

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

  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.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.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.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.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

import java.io.* ; // input output 資料函式引入
- X# v  c0 p" R
* ~4 Q- i" X4 B8 i5 l1 E, I, cimport java.util.Arrays ;2 B- W" g9 b% X# t; v2 Z
6 f  W5 a+ D: X3 j4 F7 C' s

( D# {5 V5 }! ^% Y, @+ j
6 K7 c0 p/ j4 i3 Z9 S0 B2 vpublic class JVD103{
: C6 F6 Y$ W* d3 v2 i5 p/ h2 U- G' W" Z2 q* A; G

8 v7 O' S3 [9 F1 W7 f: N* T/ M4 z. o  d+ @3 S; N
        public static void main(String arg[]){8 l6 [* H* y" g. O
/ f8 j: g  {  f; O) r# G
        : Q) t& `6 r. n- I9 K
4 E  B/ _; j: C% X& x7 `
        0 {! N2 r" e- Y& l: g+ Y
. B, N0 e, v% t* M! e# x
                System.out.println("請輸入欲產生之亂數個數:");
1 E+ {4 V: H  z2 Z) ]' p7 w# t
3 N3 Q9 f  M( e; F+ F* g: b# O4 W: j0 s        
) s: V# Y; k; z/ }0 a, V  ]. C2 t4 z* o  W
                int n = 0;  //輸入要產生亂數個數 並初始化0 s, n! e+ H, o" Y
6 k  _  ~7 l: j
               
, p9 E0 s# X" m8 u$ `; f3 |; ~) S% e( a/ N
                //使用到io 一定要加上 try catch, @' K2 t. h% W1 u- h$ N

8 ]0 Z8 J. g9 G1 }+ H                try{
+ y& o/ g) @# s3 o3 {0 X8 F
# A! u$ J# ^1 i9 i- Y7 b. }" s; q, K                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流! {+ t$ ]" d4 a4 H, o* @& ~% H
  p. g  Z: |& \) i" r
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
6 g5 c+ ~( h/ x  m) N
9 q1 p0 g" q- ~% u* _8 Y                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)& p0 T6 c9 a2 K! k2 i5 d
$ @1 `" J$ j; M! c
                }catch(Exception e){}7 R3 |. S+ W( `$ ^+ }  I
! S, j" d7 Y( l; u; g! x
                2 |  ?7 m, d# V8 g( t
. |& E) j& ?- a9 Q6 n
               
& @. H& i4 c) ^: V7 ]/ f
1 X- F6 }4 Y- b* W! y) A4 a# ]                int Num[] = new int[n];//產生n個亂數的變數6 P. R- z9 P2 |

7 K. ]' r* W; B) V# j9 M                ) f- Q, q9 U6 i: W1 V2 V
# x$ j4 D/ q' u1 ^- f' S2 `
                for(int i=0;i<n;i++){
7 V9 ]- _# f1 c5 y
( L/ i# Z8 Q8 U6 m2 ~+ o                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)( Y9 F" ]+ X) }$ W

1 y( ]6 O2 G4 x# \0 \; H                        //System.out.println(Num[i]);% R  Q% a' K/ j: J6 I9 X+ p
9 R- i9 M: i% u' J+ U% X' `0 M
                }
! T9 _7 h/ x& A2 |" j# R2 r. }
  i& i8 Q/ |5 d% M  ]                Arrays.sort(Num); //排序3 R$ J! I) }7 G, b2 @- y6 J

( j9 }0 V/ _5 _                ! o2 F2 q7 J' \! H
1 @/ t2 o% H, _4 ^7 f! G
                //輸出  E( D' V- ?# m$ y2 e
; c0 k& j7 e* n% I. [' a8 N
                for(int i=0;i<n;i++){
: V/ e/ \3 X' n) J) _: O. J" E" {* c- g; h2 u' \
                   System.out.print(Num[i]+"\t");
9 L1 q( P- }  Q4 f7 i$ w) [1 W3 g% m9 I  W
                }
; ^3 j' b& X& x6 [! G* E- }
* t7 R6 r4 b. @) P. j9 a                5 p2 |2 H- p) ?/ h9 D

# v  D2 a1 X; B& `! D: |; t        }3 {& A+ K& |" Y% o
6 Q+ r% l9 ]+ M% ]3 x, E+ _
/ ~7 y  {8 q; ^/ F6 B- ~

' j( g% n+ R2 j# W# b2 ~: ^}
人平

TOP

返回列表