返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
" L% J" N: x7 y$ Z1 e5 h1 E# `6 \5 S* _/ P
程式中可以輸入值; z+ g" p2 S0 W$ G% [+ V" N
" x: E6 y0 @& [
實際寫出 jvd103
+ N# Q, \4 k4 e' t/ O& ?9 c% I
5 s4 S3 \# Q' I$ q( q! w, S' 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 資料函式引入
5 ^2 `5 Z# T- n" O& e+ R! ^- t$ e* F9 L% U
import java.util.Arrays ;
! c) e, @, m' N: p' i7 ?0 A8 C
6 m; _4 m* f3 x& u' g* _2 W+ u4 C0 n
1 r( L3 A8 u- x  N8 M
public class JVD103{
5 P5 Z* F" U* _# d/ O5 g4 f6 |& Q" Q9 x/ s6 n7 g
& L6 z8 ?) I$ ?* Z
  n) L5 l* Z- Z& u1 p( Y: i: O
        public static void main(String arg[]){) a  L4 Q; g: Y( J) r

6 T1 \. z2 Q9 T+ w4 P( s        
( ~3 u3 R- c6 Z& Z+ y3 l3 M" d6 k# W8 n1 s0 e6 i  Q7 Z
        7 y* n. W2 Y" T+ y5 k. k0 u$ j! D
0 L0 o# g1 e- d( {3 _& C/ d1 r
                System.out.println("請輸入欲產生之亂數個數:");+ R/ f- r) {, j/ X+ _0 ?6 Y
  l% {7 J7 U- p3 I5 x
        
5 I# I3 C! W/ b; z7 C6 y3 c  s
, H1 C! N+ I4 c  x+ [4 K' i0 z                int n = 0;  //輸入要產生亂數個數 並初始化
! g5 q& p+ a5 l1 p* e
; |9 l0 ]+ k. d                9 D/ \0 b# p- {1 c3 T

& D$ ]4 O3 ?# t2 j                //使用到io 一定要加上 try catch9 B, c+ Q: N7 I: d

' z6 ?# i8 e: d' ?                try{
3 s$ ?3 Z" G: Y3 E+ L9 I. [; D4 f7 V: @- H, s2 r) X/ f+ [8 e' S3 u
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
# k) B9 \& j: L& ~, C
( v  v. X5 O5 a$ V1 v                        BufferedReader br = new BufferedReader(isr); //資料暫存區; _# ]/ y4 ?# f; x, L4 K
) `) W2 S" b* }' d' k! N
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
+ F2 r2 Z% U) A( u+ i* `6 \
% r9 n: Q6 [) ?5 h1 b2 u                }catch(Exception e){}
  n: @0 ^% x: d+ m
- K1 m/ W5 A" r+ S                ' w& |6 N5 ^/ C: x% j# G

2 S* d3 r% c4 {3 G                8 ]7 L# ]1 s- y' o8 X

' x( k) c  M% V2 Q9 e! q0 n                int Num[] = new int[n];//產生n個亂數的變數
5 V  Q; ~2 {' N& t' q& k
+ n1 R' o) @3 s2 \' Q! ]. o                * H2 w; k& a, f: L
- z" S8 w6 t0 q9 O) ~
                for(int i=0;i<n;i++){1 Y' A& L2 l# v0 F

' A' z  C8 Y# p/ V, I                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
: Q  X* K1 o1 A$ ]: P9 }, D$ s6 B
$ t5 i" V) y5 {9 i                        //System.out.println(Num[i]);
' j/ F. {3 W5 q' j" H/ z1 H4 n' i% `( ]7 m# R4 j
                }
% J8 v4 r0 m9 _6 X% p% [; [6 ?5 U1 y" K/ h  l1 r  a
                Arrays.sort(Num); //排序- y' a( _( s0 o; G$ d
, Y* i7 l( w/ m$ n/ M
                  i4 g( s% n4 @+ J

4 k; S: o: L% _& r- o                //輸出
. J4 u8 m. V2 z/ t( m( l" R1 |( M* ^* W+ R7 i
                for(int i=0;i<n;i++){
- b7 o4 V- u& G3 a9 q) x  W. w( O, b% Q$ E
                   System.out.print(Num[i]+"\t");
: q9 Y3 M& I5 k
: X) P7 C3 g! {" u0 G                }$ B) D6 O4 p( G& Q' c
  c- k/ p: [3 {  \: F  D
                . P. q  |2 X" ^3 K* c# r/ }
% e$ V1 T3 _% y' [; h2 M
        }7 g2 ?$ C  n( D' ]5 t

$ `9 k3 {& N3 @1 p: l7 x- l7 F/ h& H  @
/ G) B8 u1 a5 e' h! ~" D
}
人平

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;) ?8 C8 m/ D% S% n9 {, E

6 V  ^+ k) E" T* himport java.util.Scanner ;4 [( x) [( y( d  m+ F, k

/ n5 p' @9 T) X7 t% c8 tpublic class j103* }7 ]* k2 D7 S% D

7 }: X5 |; X/ H# _" Y& M0 F9 P{$ Z9 L. H) k9 Q3 G

- b$ k9 X4 ?2 ?5 u7 B0 H        public static void main(String[]arg)
  d" g; d: ]3 s( x
: m! z& Q1 U0 ~        {' Y* Q" f! R# @( a; ?

# Z( d4 G& G8 \9 p        System.out.println("請輸入欲產生之亂數個數");( \' N/ g2 z! {$ @
' v1 r$ Z! ^7 M8 i3 p
        Scanner s=new Scanner(System.in);
; P" ?) ^0 k; ?8 n, t- H$ l# \/ j8 p) P
        //System.out.println(s.nextInt());2 ]5 U2 _) n0 c# L9 I) \
. u' m8 h" Q. p+ r
        int n = s.nextInt();
7 K3 @8 ]6 {. u- ]! X
7 a6 b0 ~+ J. {+ Z        int ar[]=new int[n];6 y$ R" l5 c( Q; A4 _# ]
$ W* }& F: |# Z1 U
                for(int i=0;i<n;i++)
. q5 g$ q; ^6 X  ?1 @
' {( R6 Q8 Q/ e& W; Z" \; t" c                {* K+ F; |* q  R8 L

) ^$ s) B: b: b$ V( S+ t. o                ar[i]=(int)(Math.random()*1000);
9 ~# A, h6 p  [5 n" ]
) I% z4 L; k' f4 b                }; t/ m' B5 K" _6 G
: Q0 n0 @. p& j* U, o! l! w
        Arrays.sort(ar);% @; h$ z9 d, s% }1 `- t3 ~2 I+ `5 A
. W' Q) Y! u# a: I
                for(int i=0;i<n;i++)5 m* ~+ {8 B- }/ w8 Q1 p

, M: {# }, E0 i3 U                {
1 X5 v  @* w: g# X0 M+ k. h: S# `
3 u( |# o# a0 D# ~( e% u: M- ?                System.out.print(ar[i]+"\n")        3 ?! ?1 L7 p1 c- o$ ^  M9 }% U1 E

* s* c( F! T4 m2 R: W                1 X, z) V' H9 k
. ~2 X7 c. E( l' |/ L
                }2 ?  B$ _' b- m3 x' D( Q2 z+ w

. A5 c& n( b3 `+ ~        }
1 |" y: `' j% U+ j5 w
7 L; ]; p6 l% x7 F: ~) i8 ^}
人平

TOP

返回列表