返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
% S3 B2 u. l* x4 o9 c) n# b1 _8 o! P$ T
程式中可以輸入值. D" q( ^2 A5 O; `" A
1 ^$ p% I$ V* k0 h4 i1 l- j
實際寫出 jvd103
. x- f# M/ r+ U5 a* Y4 a, ~! x9 L
( c" o$ l% U) E! u& F- A& V使用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 資料函式引入
. P. {" w# R, g! Z8 \! Z& o, [4 h! d( M0 z  W
import java.util.Arrays ;
8 P9 R! l% P# S* A5 i, ^. ]0 h) O3 f: ?! d1 e; F

1 i8 v% A0 B) k% @% N
# D& ]1 `7 Y0 U- Q! hpublic class JVD103{
' y- K6 a5 i/ U  N: E9 j/ E' ^. G6 O4 @/ x. y

1 c+ O1 L* x$ t: F- o) Q1 M; `" N+ z: b1 [
        public static void main(String arg[]){$ l: C! O# j- ?3 g4 ^
$ j# [1 z) K( Y5 N
        
+ w& v# s7 d: A" H
2 J3 l( S0 l1 p' C# O! A8 N        * y; y& |$ O2 u% r
' v! F3 n% h+ v0 r
                System.out.println("請輸入欲產生之亂數個數:");0 I! \8 v' s  h! o  G; k3 S
& Z' l7 P8 w- T. O3 W
        5 H9 t0 l6 r4 v" j9 t
$ \9 o5 G; [2 w5 b/ Y7 n% A
                int n = 0;  //輸入要產生亂數個數 並初始化: _1 c+ D7 B  g# l8 N5 w6 S0 I

1 B" @- x" Q% h7 B% c! ?( N               
6 ]/ d& W, P! h, n* [& |
8 t5 a* ~3 l6 h5 w. {% s$ W1 _( g( `* ~                //使用到io 一定要加上 try catch- [0 X* D; T$ [. f& l' E/ l
6 F" e% X# ^, H+ }# n4 g" f' I
                try{9 }. p9 v* h! U1 l: p& ?% z

5 u$ x' G( X9 U8 s* D7 p                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
* H8 }# S/ Q7 N& e- W1 z5 z
1 A" |0 I5 _4 l/ ]" F8 s4 d. ^6 \                        BufferedReader br = new BufferedReader(isr); //資料暫存區- u7 S0 K1 U! G* e! s) F+ Y
/ F% |1 R2 \' @# b" y+ M  L2 A
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)9 _" |" r  H& \6 b& ^# z
; y! U# _4 A8 u7 e& }* {
                }catch(Exception e){}+ L# q( k0 o' Q3 t+ E  H" i. u

( x/ \( G. d7 a               
* R- [  X! O$ Z/ p" g# {# P) F) ?! l" n. f: I
               
. j8 h% [2 P% C! E: B( \  ^  e7 }" B% D$ p
                int Num[] = new int[n];//產生n個亂數的變數
1 H& G# g& n$ _  _. T) ?/ U* {0 S& t" Y" W: A/ M( f
                ! x" I% K- I# ]1 @& l" K& m

1 U+ L* x0 M, B( f                for(int i=0;i<n;i++){+ S4 G+ O- [/ t- P+ U6 {

+ {: v* x3 x, W) ?                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)& J! `% Z- F: p. a+ X8 j

/ @: {& L. W5 M' B                        //System.out.println(Num[i]);- n; E6 [3 |+ y/ N- M3 z
0 e; b4 Y. o6 y
                }
9 Y; q! O  |+ d9 l& x
7 j- T* l% e  J0 C" P8 _                Arrays.sort(Num); //排序7 _9 x. B, O9 ~1 R) G' N( J7 m9 N- `

5 {3 \  W- H9 o( |% ?; y- R                , X- ]4 H9 g/ m
. T# G; Q. K! y0 x# o  O
                //輸出3 v; l1 y/ j/ U; A$ ~$ d

8 Z' V& |. o: j( L* W                for(int i=0;i<n;i++){% Z2 _9 p2 _6 {1 m& h/ @9 W5 V

$ a, i& r3 N9 J6 @# i                   System.out.print(Num[i]+"\t");
0 g$ h( o) i, |/ P& B4 y  @' |* s5 Y" X: [* a" p/ G
                }
% x; f; A) s5 x" D6 f1 c7 Q- \6 C. U
                : x/ d1 R/ J7 w, F/ L" K

8 L' F8 Q9 i) g* j2 u1 S        }
. _/ p# b! p0 H
8 ^3 @* w! o: u0 {! p2 P
1 ^+ u+ x, c$ o( d% g
  r. z4 w9 X/ t+ J$ T4 q}
人平

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;5 [& v! \2 n8 _
" C+ i- i1 ~; v2 y2 v
import java.util.Scanner ;
( _: J; N7 D2 x, c* V: U+ p! H& G, M& x) D, N
public class j103
6 z( @; Q$ S6 D1 ^7 |( }4 q2 q" y4 f+ q5 ?9 W
{3 c0 F4 D! D* ]; L6 T1 t
& l6 O/ N7 K8 {, v! f
        public static void main(String[]arg)5 W4 U) D. e  c

5 D5 _$ I+ z0 \        {* I4 x- u  D% Z& S, {) [- c

  k1 B; `1 [* h& I: K: I        System.out.println("請輸入欲產生之亂數個數");; q5 }2 y* q& a6 D4 e* P. p

  r5 M  M/ z+ r' |6 z' n        Scanner s=new Scanner(System.in);
  \  `: T; i6 [4 b( T
: ?0 P  m& \, }0 m2 i" X        //System.out.println(s.nextInt());# o: j% v) Q0 n5 `( l- I

- Z5 T4 d2 C! |/ [9 Z# a        int n = s.nextInt();
8 w& ]! @* f5 v. f" Y% r) \1 k* [7 i. S) R$ {( \4 m! U8 \) Q
        int ar[]=new int[n];9 g1 Z) |7 Z7 N5 J% U

( l1 F, n0 G2 m' l! q: M# e* I" T+ w                for(int i=0;i<n;i++)
- f5 L* z( h0 @
. p) f" Y( Z8 z7 T) g1 m6 y                {6 D& s1 e1 v6 a

  \) Z' g9 T1 T4 z+ ~4 c% G6 J                ar[i]=(int)(Math.random()*1000);
' I3 ^, o8 J$ e# x7 d* s
" ^2 g+ c4 B+ |                }
; ^- l9 i. K: o8 W/ N
% q" L2 @4 c" E- G7 K* U& V* R        Arrays.sort(ar);
% Y5 G5 D. [/ g% P
' ^6 C* Y" B. l" m; N! _$ I8 ~  J: M                for(int i=0;i<n;i++)% H. i, }+ C* Z0 Z6 m

4 g# f9 T+ N. L: w0 j                {
5 E! f* ?; w0 \8 S% n+ a2 ]2 {6 B- F, G1 z8 s( q
                System.out.print(ar[i]+"\n")        
3 [6 A/ s( w  q5 }5 P8 g
. O, e; |0 B2 |, D- n                9 L7 O. H2 x- B
; Q& b! A, O5 Y( f" r& R" k" E3 A
                }7 r' ?! n8 n/ s1 y

" d7 d6 C7 N* W' u1 Q. m8 C3 F: i$ [        }
: ~5 V% E/ S$ n$ G) a
% L2 t! `8 P# S}
人平

TOP

返回列表