返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
1 l6 q* U4 f- E
2 c, G+ N0 D3 D5 O9 s, [程式中可以輸入值/ n( N/ R; k0 W; H) D
1 F. j9 f" l; c1 M) @9 D/ Q
實際寫出 jvd103
; u& h/ B. U% d& [, `
" T- f1 C' h6 G! l4 y2 X/ `# n使用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;9 |9 C" v* R2 n& X: l' |
  _$ w; p' [5 {- O. x, [; ~3 n
import java.util.Scanner ;0 k, E5 @. d# }' C! E# o
2 B; m: ]$ C+ i7 h2 p* H
public class j103) d3 _( ]* }9 ?  S+ {4 |
& s" b" A4 B" U8 `3 G+ C
{0 Y$ R; Y$ M8 N3 z9 m

7 X1 }' n# W! S, H5 x  ^        public static void main(String[]arg)
3 C1 e" H/ a! x# p, w% N) G) x. q2 U- }( a/ b1 k0 v% g- e4 i
        {
0 B- u/ ^" P3 i
. c; m5 B: ^# M: F  V. D* v        System.out.println("請輸入欲產生之亂數個數");) C9 s3 a' R$ G8 J  V
& b- C  e: {' v8 H2 M9 }
        Scanner s=new Scanner(System.in);
' ]( f. b9 b: }' a, W: `
4 U& b: r7 h. ?. a# V6 O; ]4 e        //System.out.println(s.nextInt());
! n0 x7 ?6 v0 W0 T) u
/ i+ ^0 X8 k( D        int n = s.nextInt();) X! E1 w/ l# g

" o# `# B: v) B; V" s# U        int ar[]=new int[n];
$ B6 U' V/ h  i) X+ p. H
0 ~$ Q- z# F7 m4 J1 g, r                for(int i=0;i<n;i++)
* h$ i7 |1 v% p% [2 [# S0 ~3 X9 \, W! ?6 g' t
                {5 O! a1 c* `+ [- A2 ^/ ~

5 h, e0 J* H! o                ar[i]=(int)(Math.random()*1000);+ O' D+ b, H: b
, y2 Z5 Z9 n# W5 W  G  i, w4 R+ b1 e* D& C
                }
: Y& Q3 ^! W% D- Y  V/ l4 x* r# f. B$ y
        Arrays.sort(ar);
* o4 P5 @0 @8 f' ^4 F& R& [+ E3 X7 h* E- |9 S7 l
                for(int i=0;i<n;i++)
) j3 O8 [6 W- _) l, a3 R$ `+ [. M1 @
                {# E# p/ H* k1 Q. i+ w' P' o

; _3 f+ o* s) ?$ x9 k* R                System.out.print(ar[i]+"\n")        " U9 J& |( U7 U; M
% q$ y. Q0 r: L& B
               
9 m: v1 c7 {* n6 t) D7 N( G8 d" d0 q" v: B: Q/ b; Z
                }7 f- |  U8 F$ H5 m+ M) X7 Z+ y
& e% h7 F- S( h1 D7 P0 x# T" Y
        }; C, t1 e% B  s
5 G( X: F! m- v" m! i  @& _
}
人平

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 資料函式引入9 S# Z% N  B4 F9 D7 W
4 {3 h  C5 _6 K7 `7 E9 o4 z
import java.util.Arrays ;
+ c4 x# u+ j- L3 n8 _( `8 j+ ^
6 q. g) E9 ?$ F$ ^, D( E& b/ A5 S  F0 y9 Y% u& T2 o
: G6 F# Z- j! t, C1 \
public class JVD103{
; M$ ~. c$ |( J
2 E) u. ]9 W' u! {7 A
" Z& `" ]7 l: E, a1 B% X) R( n% i3 H2 Y1 S# d# ^) ?6 l
        public static void main(String arg[]){( D4 _! s5 y$ ^2 A, f# L
& I& q" t3 f! _% j2 d: p  p0 @2 S" i
        8 ~1 `+ t- ^3 W8 n

+ T+ N7 k/ f# c7 a4 R! O& @        . N& F& u9 c% Q" h' d+ F
8 s4 m8 ], ^- B8 S& h! c% W
                System.out.println("請輸入欲產生之亂數個數:");' A0 t# m5 [, `' H+ l0 A
+ u2 L% S6 `& B# s9 K# l! C
        2 y6 ]$ s( ^4 [1 C( l* d6 O! U2 G6 f
* k6 E, w( z1 _" }  {% n
                int n = 0;  //輸入要產生亂數個數 並初始化
7 n" c9 t/ p" w  j/ }, V: D1 u  O) w0 F# {
               
2 p* w8 P6 A* o+ y) A7 f( f  s: P  N0 |/ O/ P7 o
                //使用到io 一定要加上 try catch
2 g. f) p& h9 a$ }5 l
5 n, o2 D: k- |, h7 |, |: c. E                try{
4 ?9 T1 u, h% I+ c' u; s/ j. u! g5 z
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流5 b7 A9 K  Z# U+ [& {  w0 D

7 p  ]3 A  Z" t* o( k5 l. g; m                        BufferedReader br = new BufferedReader(isr); //資料暫存區
% a# I( k! J9 s# x# E' d" @: G# A% L6 ?! }2 k# A
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
' v9 {8 s; _" M3 }6 M( J, H9 g1 G
                }catch(Exception e){}/ Z& w* ^3 `: r+ ^: f6 p
+ |5 W, @+ y# @$ v" m) Q1 S
               
; B  |; Y' s- v, R- v9 o) a+ }- b
               
6 D0 d6 v+ _3 V. R6 m( y2 T: `, S  G. @7 J) U( u* Z
                int Num[] = new int[n];//產生n個亂數的變數
( ~0 E* K! w* V" s% y" w
9 W" N7 s0 y1 L- J5 r& Q                9 m- x$ U1 H: p; k2 o: ]' V
9 X  p* O$ u  e# M6 H! I1 D
                for(int i=0;i<n;i++){7 J' X4 Y" Z- Q: b' {, ~  ]

2 w2 Y# K& a2 j8 s$ A: s, |: h6 K                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)& A& k) d1 X2 A8 v
6 I8 i! v& ~8 m. r
                        //System.out.println(Num[i]);
- j# `# J- Q) u. C# U; I9 k( [# V4 f1 }' ]( n# O0 k2 t' U
                }$ t; r9 f1 f/ Q* @) q: B+ z: _0 A
8 o3 \# x9 q; ]; {/ R! T
                Arrays.sort(Num); //排序
& B/ a6 `- o/ ]3 S4 r
- _) m  U* v) c- U5 p6 C               
4 H$ U; ~/ [' N
2 b6 E2 s3 }2 D. v! b                //輸出0 M- I' p3 X0 C, T8 t1 n
7 H5 E- T- q/ N% O) y" y
                for(int i=0;i<n;i++){' y: _; j" {5 ^$ v: ?

, f' H4 d0 M; p2 t; r                   System.out.print(Num[i]+"\t");
- h8 D' q$ G* h3 k, s* F! Z1 L5 V: i- W/ R. W2 `3 m5 E8 X
                }( w, g1 f8 z: P: I9 H' y8 x

$ }, `$ H& @8 ~                ; ~' y* O% a/ l/ R1 @6 V/ J. ?3 G: ?
% |' ^4 I1 F+ Y# T+ T
        }
+ q- R3 r5 o" V( t1 n, V
+ q: b" R3 J) K/ Z& @. `. I- g2 h# F  ~, s7 _: f7 Q" {

3 C* t" j" R' d) {/ H}
人平

TOP

返回列表