返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
- o/ G4 o- B; p1 m- p) m7 @/ G/ ^8 V& k! y
程式中可以輸入值$ }2 [; ~1 Z6 O/ p

1 P2 G, b9 S( C1 G實際寫出 jvd103! A+ I8 F0 E: [- V
0 A, u: x/ \4 I0 k
使用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 資料函式引入
$ ^* F0 c. \; u2 ?( b5 U  y) b$ S# o+ A
import java.util.Arrays ;
+ |& ?: f0 A9 W$ {. u2 g, x) N- [4 k4 C: j8 A

% M* u$ B/ v* |! m, n
! `" ~* o& J: F" t' kpublic class JVD103{
: j9 x* v. r% F7 o% v" r0 z6 A# }! A! s3 Q0 t  t

+ Y, a& i8 `! I3 P% \" |
, y2 z" S4 R7 Y; d( {# b7 Z+ D/ [        public static void main(String arg[]){
1 n1 q+ k1 [2 S4 H( I: L
4 N3 X5 E: \: Z$ s$ ]& k        
' Q1 C1 \( ]3 S5 X) m# N
* Q2 Y; [- u  c: A% `        7 T, ~) D+ H7 w) [5 ]
! n1 y9 P- b4 i3 p9 ^. Y, Y' w8 u
                System.out.println("請輸入欲產生之亂數個數:");
+ v5 t8 W" C% @+ Z/ U; \6 i
% r# [* Q5 O9 Y4 a4 v        
# {- p1 T. A6 d7 Q# n% y
2 _. ~8 H* q, G- k: {% {                int n = 0;  //輸入要產生亂數個數 並初始化: ]& S. l$ n; t: G- g

" ]+ w& p+ ~2 `0 H3 q; [. f. _               
1 H* h3 n; I9 C, j! K  b9 Z& }% p- ?% }3 \8 [
                //使用到io 一定要加上 try catch
" c5 }3 m! E8 A/ `& e' s8 @7 y) ]% f' t& O5 ?( W9 s$ ~8 B2 u7 ~7 T& ^8 P
                try{1 j' I( Z' l' M$ s
  }* G0 O3 E! A6 I8 f( p' H
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
$ v+ J  [2 z- J% o, R2 ?( S
; z: X+ A3 l. e  T, I- W* x                        BufferedReader br = new BufferedReader(isr); //資料暫存區
9 D) \4 H+ u1 b9 G9 ?" X* w
4 u0 T- S! ]$ l7 q8 A5 k: F: ?. ]2 p                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)* r% y7 ]9 _9 k5 k, k. @

* o. b& C' U0 v) A( O" t3 W                }catch(Exception e){}7 Q7 ]8 V# q1 T$ C9 r8 E( k

; X' y9 x4 ~  \! P                / V, L' f& N+ \; v1 }
6 M: |2 s& N; n( z/ _0 l+ k
                / H3 ?( S. V4 r
" O( H1 E# ~( I. a3 T: W+ \
                int Num[] = new int[n];//產生n個亂數的變數
8 D0 Y  {. m5 @7 Z* ]& s5 a$ q: v! Y9 ], t2 p* U9 Z1 M
                ( d$ `+ v' g* u: N

2 b1 o' P/ }* `5 ?4 }+ Y                for(int i=0;i<n;i++){, ~0 v$ U' G/ a/ O+ d

) [# G. f. Y. {- t7 p% f) l                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)9 g4 f( ]' V! b7 |, Z" |/ _* |
+ L# C. Y7 P4 F% p- R+ ^
                        //System.out.println(Num[i]);( E' A" I; n1 [% r2 i% `" U

  x9 c6 a" }* E6 u% s                }
# T# H' F) T6 c; J$ r- F( [# l4 D/ f) v0 C# e( M$ G
                Arrays.sort(Num); //排序
4 k- m1 D, }8 z, J8 r
' k: w3 ^3 r/ ^; A/ ]3 f                6 M2 P, o, E2 I+ s3 q! X, ]
& ~6 `; w, I" l, |* H. x
                //輸出' K3 k5 I& A. U$ u

/ a- T! m- @$ K6 v4 B. B                for(int i=0;i<n;i++){
5 m2 Q% ]: E( g& U/ h) l6 O* F; H- `
                   System.out.print(Num[i]+"\t");
4 K+ D8 l* X# g! v, u$ X" A8 b2 x: c) ~
                }  j; L( ]/ }3 [5 S1 t" g: R; p# ~

' I# C. Z( k* P' ^  Q- F* B               
( c& e$ |4 Z) @1 u) l! B9 D# i" @  Q; M9 n3 @% M8 @
        }1 {4 |0 O, y. Y* G  G# }4 ~
! w9 |0 |7 d% Q- u2 M8 b

% K  y  x& Q7 I* W
& ^; Q: ~0 R7 D7 {% b}
人平

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;2 y+ k: i0 e, Z  S3 N) S5 y$ z

- j7 Q3 ~9 S& \; _9 ^( S" p; Q3 Kimport java.util.Scanner ;. L6 J1 p7 c; P# k- I1 D  C8 \( Q! t$ ^, W

3 u' W8 P7 m1 W% t% X! Rpublic class j103
0 u9 q# w# j% [* \0 X* d" X  S  _0 t$ ~: C; i7 s  H$ E1 y) `: F
{
7 v3 I# X4 Q: s6 T! N* O5 ?4 a) W, w, k7 D; _+ c
        public static void main(String[]arg)4 b2 K# `6 }8 T  _% J& L8 a

0 e+ O9 m1 L' b+ j5 J/ i        {$ z) v* [3 X. Q
# c! g9 p- y9 m6 K
        System.out.println("請輸入欲產生之亂數個數");
) p+ {+ w* v' K- o  C
8 W( t/ f5 @. ]5 u        Scanner s=new Scanner(System.in);
0 b- q' K2 j! ?/ q# J' v0 ]0 l6 l8 T- D. R: E
        //System.out.println(s.nextInt());
9 M  H, J3 U2 V/ e
" S( P8 l2 F8 m        int n = s.nextInt();
0 J3 t1 \3 O  b
1 |: E  s1 j, {        int ar[]=new int[n];+ P4 e1 `0 U; F7 }  w  p+ [8 t4 H

  o/ V4 c. D: i; F* r                for(int i=0;i<n;i++)
8 U) q+ ~4 \0 @: p4 ^- P# l
7 ~5 a; _5 j7 z5 I. \$ o                {
4 t* c0 r8 z9 B" G/ G4 Z! W/ W1 C2 C' d+ f+ y* X+ E# u
                ar[i]=(int)(Math.random()*1000);
$ T" `& [9 M7 A5 N+ P; Y
- O) J; S: r7 x# T: r* J: [/ N                }
. I4 l; {+ `; n1 V- ^- F
7 j) D9 i" _3 S$ }2 g        Arrays.sort(ar);: o7 t5 j+ Y. G: V) s9 ^
* H+ u; R! ]' I: S- K! U' N+ c
                for(int i=0;i<n;i++)
3 J, Q: z( N( ?0 B5 s; ?0 B" U- H. B- R9 g
                {7 N; I( ]# M$ O
$ d3 I( L+ g3 `/ a6 Q# x* F
                System.out.print(ar[i]+"\n")        
, u* k5 {7 d$ k
$ k* @+ n% G; }" s3 Z8 t5 ^               
7 x. I3 L* \! d* p4 S1 v8 l! U7 G; E8 Q% z2 y; z
                }5 w7 w% D6 u, w4 v* w; |8 G# D: k

. Q% ?5 G+ S8 t1 U: L        }" \, k6 |% k& d: `3 {

0 F# t% N& U$ w: c# S}
人平

TOP

返回列表