返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
, f6 e) P( e& a1 I! J7 z( f  w* i
程式中可以輸入值! n; j1 ?4 U2 m
/ ]7 \# b. K$ I' |, m2 [7 _: R
實際寫出 jvd103
% `3 o* ^+ ]  B: v( q! \
2 \8 J3 u& R) @1 _& {使用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 資料函式引入
" O/ s' {+ T% @
' E2 H6 j0 O; s) d! k" Mimport java.util.Arrays ;
1 _, a7 J( P. s- i* Z* V% H- M( o/ z9 A* H9 e

+ W7 e9 ]: f' N0 X, {" v  Z  c2 _8 Q; X% k7 ~+ i% ^) W3 p
public class JVD103{. m/ Y! x; c6 O4 \4 g

0 `- F2 Y8 n# i0 _# \
( O1 }0 l/ ^! Z/ k( v" \' g* ]) _/ e
# Y# y. j6 k! k& O9 x7 v        public static void main(String arg[]){
6 `+ H8 ~. E; T
& r7 @, \  Y6 W) N; Y1 ^5 U        & N) y* `' n7 Y* ~% ?
2 f& D4 ~8 |3 T6 h
        
6 k( e0 {" V2 ]8 H
* E4 G- n0 g( n- f  o4 C3 h  q                System.out.println("請輸入欲產生之亂數個數:");
  ~7 {0 o, `! Q6 t/ F! E' V, g& w* x
        
+ [; Y+ f6 p% I; O; z) A
: r# S6 x6 ?1 K: y                int n = 0;  //輸入要產生亂數個數 並初始化" @, O& g# L4 u7 l5 P1 ?# M' m
4 Q% s$ ]8 v$ b/ R% L  W6 @
                : O0 ^" p- `4 o# a/ s
( R" J% n* J8 I, M3 O- a0 v
                //使用到io 一定要加上 try catch2 [& D  r+ {2 x  Y/ A% \
" e9 r! `- X& }2 i: I8 q
                try{
+ J1 D! Q9 ~) @; N5 Z. Y5 }
: l3 M3 J& Y8 R( C0 W, O3 {0 s                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流$ h. Z2 B( z% `0 k. C
5 T) }$ R: S! |% h. N) z
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
. M& x/ F+ a, K" ]2 Q4 ]" w' S; S) A# d' T1 N' Z
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
7 d% ?& u6 x6 Z% w4 `: w0 g
2 C7 V. l$ B9 w! j* P  v                }catch(Exception e){}4 X9 ^' Z: c% H; J1 t

8 v0 R: ^! y) @+ X0 `( O                9 b* r% l( G* M" @

! s# d* l# K2 i0 W: g" X* y               
) e4 Z& U0 F! Z0 a0 _/ g- n# Q& o- k5 Q( b
                int Num[] = new int[n];//產生n個亂數的變數
' ~. w) P: {6 `* A8 l/ ], ~1 ~5 j* Z) [0 P( C
               
& W) p$ E9 L+ k1 o+ Q3 o! h( l% b- S* o( ]- E% O/ J/ k8 z  b2 r3 _9 d
                for(int i=0;i<n;i++){
; `7 ^, }( F% n% n- w; {. p4 o( \5 D% V( M
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
/ U3 b7 P6 @  |4 m1 R- I1 \3 z2 ^9 L0 s& i+ [& A
                        //System.out.println(Num[i]);
: k, y, F3 H. B  {2 ?  c- V7 R( V
                }
& U& D* i! u1 t6 s# p" {' ]4 o# B# u! O" L: R
                Arrays.sort(Num); //排序
# O8 ?- y; J$ z$ d& M) L6 N! E
$ l% \& {  C1 J  R* m               
. C# ?' Y+ y- q: |6 y2 v; x: L: }* p1 }% M9 ^
                //輸出: p) N% t" v$ c

) l3 L% S% L, `% ]+ |1 t                for(int i=0;i<n;i++){
4 m- j- j% ?9 W+ c. R* V% O) `- t% ^4 P/ Z2 X1 @
                   System.out.print(Num[i]+"\t");
, N0 [: q! s  M" x1 y( e" L6 a+ w+ c6 I7 |
                }$ M( ^) ]8 t2 S. w: [. \) ~2 a1 E3 H
+ X% C( \5 Q7 Q/ X
                + v6 m2 m. j) t; i+ g: O+ I" w
  w+ W9 I* N# s% K8 [+ j; Z
        }
0 A7 Q2 g' c$ J- x% m1 h: s$ p! @7 ~; v) i0 ?# M1 l9 ~

, c2 r  `! O4 a9 ?8 m6 W$ s, N( d; t- H# I
}
人平

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;
; r/ `0 k7 E6 D  I) G3 G' a& {6 x$ B8 e3 b, U# p
import java.util.Scanner ;- }$ B9 F# E- V- a9 y* p% S/ ]

" S! j! X2 |. Ppublic class j1039 G, n8 G  C" G( `6 @

& i5 h7 S2 A4 ?8 r5 Z0 P{
' Z% }: x( ]% p" U  k' {: @+ K7 V! R: `1 z- x2 |
        public static void main(String[]arg)2 X/ V9 g$ t& F* l9 S8 t
' V1 v: g1 s5 C. V& f) ?
        {
3 G' a  L' F( Q/ f7 {% Y9 ~& b
& b1 t( e/ W7 v4 x0 R; _. b( I        System.out.println("請輸入欲產生之亂數個數");6 s/ W. |/ n; i7 t$ d& g% K: q- H% B

  L' P5 S0 w3 x+ r        Scanner s=new Scanner(System.in);
* D3 d9 K6 C% Z
2 S# e3 \7 o$ I4 z" |        //System.out.println(s.nextInt());
7 k: L2 P; y2 [  o0 @5 w
4 e, b- z4 O: u4 N        int n = s.nextInt();
! H5 J, c# K9 q. E" c# c% w4 V/ |0 e7 b
        int ar[]=new int[n];
9 a' U" n, D, P+ V4 K
! C) s2 u+ T1 h                for(int i=0;i<n;i++)
% O- ^2 I6 H; f8 T& v3 R
2 K, A3 ]" |/ R* g                {
; P" f3 A# P- s' ]% Q) h) b1 x# E* ^# C! o! K+ M; [
                ar[i]=(int)(Math.random()*1000);6 ~1 b( h2 ]" L) _0 A
6 V6 L+ T7 k1 X% B/ ?1 ^1 |( H$ N% i
                }
: H! Y9 Z* C9 l
: |+ S6 O- ?+ u% r& }% v. Q: X# u        Arrays.sort(ar);
. I7 y" ?, N. l
6 e  E) O0 v2 A0 N                for(int i=0;i<n;i++). u+ r- ^- E; F& C. h
  S1 @4 X$ H0 c3 R
                {! z) n( o: W  N& q  p( Q1 y
  I/ N7 I- M! ?! G, V" j
                System.out.print(ar[i]+"\n")        1 N7 R5 {% N0 a  i

4 h0 `  R/ s2 P: l                5 t: X4 p2 @6 V4 z" U: s
+ b1 }: Z1 E2 a0 l* ^! M  r
                }4 g& R0 u* C; Y4 F* V4 |3 h

9 G$ O4 E5 O5 n. b+ G# z) \        }7 Q( p' n" Z/ M( W. E% Y4 c, w2 j
3 x4 e9 A1 G/ R" j
}
人平

TOP

返回列表