返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 . U5 h2 _$ Y' b$ d
, E1 h9 C% R) i/ D( q
程式中可以輸入值
# l7 n5 P2 k+ G$ q2 B% p" V2 e1 w& a0 _3 z
實際寫出 jvd103- o+ n7 X( t; ~, H, w6 f

: u1 h$ V" d8 A7 ^' x9 p  @! T使用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 資料函式引入
) d( V! w1 r  `% I7 J
( W" z; T  b5 M" T+ vimport java.util.Arrays ;
- F6 t) i8 [/ Z
& m$ h$ q3 c) D$ c' S
* G0 {8 ?. p' V
9 y" N; _/ ^0 Q) }( w  W! t: a- A3 u4 ~public class JVD103{
0 k8 P0 ^( j+ ^+ C& L) F6 n5 ]
! \/ r; I: K( q  O: N, X3 n# d% u9 M' o- ^; _' s5 z4 S

! m; O$ n# y: k        public static void main(String arg[]){3 t6 D$ J+ ]; g7 T4 }" v8 h

$ P0 G2 Z7 @7 r; l5 o) x+ k        
+ z! A, ^$ d) I  Z$ s% p, W7 N0 i4 B0 k; y- E
        
- h. i2 R4 e. U8 ]# L: M. l: d) g, q: C* I
                System.out.println("請輸入欲產生之亂數個數:");4 @! T. F  H' Y: A

; ~% F: j+ y8 y3 l5 q/ ^1 ~        # _4 T& p( q2 q! y
. F8 [* C/ v" s
                int n = 0;  //輸入要產生亂數個數 並初始化7 {5 [8 ^+ J7 E! S
7 u; w% w7 [6 ]4 w2 [
               
/ W- q& }4 E" i$ M! U( b& C( D5 \9 t- K' c0 o
                //使用到io 一定要加上 try catch
" k0 s6 h. B) o4 U# L; I. u% s, y& T
: I' T+ ^. E8 P. u3 U( C' e                try{
- i. `% p& {  a5 y* L, Q* ]5 _) T: W. D( p8 J! P
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
2 G( O1 U0 }3 I& O) f" S  U- v- h9 b! {4 v4 g2 w
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
- O. U; r; T9 D0 ^; L
+ a& B, R; i/ o/ s) R1 w                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
8 Q; V9 q2 I' z# e
( X% @) F8 C& R/ p0 q" @                }catch(Exception e){}
# k8 ^5 _3 A, j" i& ?# y: N: b- I+ x* N1 \2 g
                ( g4 m# Z) O$ _. \- A( A
" f0 [2 j7 x4 E
                9 V/ I1 E2 B, N' m7 w- K9 D
4 ^* Y; G! x9 q4 z# z$ s9 ^
                int Num[] = new int[n];//產生n個亂數的變數# X, Q  K/ [, s, W( O- X* Y
& k4 C8 Z+ d. `
               
. Y( {# u! x* F6 [2 D$ O; T2 l- ^% [% g7 e/ f: d' Q/ A5 j/ Z
                for(int i=0;i<n;i++){0 [# E; X7 [6 M; C' c9 r" E
3 N. D& t+ \. z7 C* k3 a8 H5 E) G
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
- i5 o* f- `" H) `
4 s) m& N) W4 R0 M                        //System.out.println(Num[i]);
! u" U" I: b( X2 U4 d1 h: [1 i: K. u- Q% z
                }
3 R' e% U$ u- Q& f) Z) Q2 O
1 F7 t3 |( J/ V                Arrays.sort(Num); //排序
" V$ e' X6 ^% q  t, h! a
4 [. i  W/ Q4 ]& E( `- s$ ]$ A                % [  s, a8 z2 _( N; w* [
- U% @3 }; D0 g% F
                //輸出
! H) D- D* m5 O0 x' X) N0 p9 w0 S6 w
" ?8 n# `# K- L' [$ u2 l$ p/ V4 V                for(int i=0;i<n;i++){# k' L* e! P7 C$ {7 n) R

" n1 G# ?' c- }# \9 V                   System.out.print(Num[i]+"\t");8 b$ T/ K7 o: i- l% ^' e
" b0 F1 F3 j8 L, V  X4 s
                }
# M3 \5 T% q2 B; S. @( ]
# U# I% l9 g. Z                ( ~4 {3 p$ A1 \4 c
4 }; E* r6 s: O, l# v) c+ p
        }5 `/ U1 {" o  W  R$ \

! X3 s  z' w; I, h; c2 v/ K6 \* e! X. u
1 p' Y" O. x/ k3 B  g
}
人平

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;1 _7 p* T) |4 X2 e5 ]4 I- U
. J. }8 p7 W5 ]1 |  [
import java.util.Scanner ;1 s: `5 G/ y- e9 @2 G9 Y

' U7 a% O: d6 N! Q: q; D  tpublic class j103* @2 b4 Y  {* ^' S' v
/ E6 N4 A# G5 d7 j5 g
{
$ [: S& x3 b  K' ]( b8 n( Y) D8 E% W0 Z) n+ n! `/ m0 t
        public static void main(String[]arg)$ C1 m3 D6 w9 l0 B
7 m; H/ I/ ]! y0 L! w% h
        {
- W; H! g0 }" D# _& P: B+ o5 c  Y4 l3 g) u$ @
        System.out.println("請輸入欲產生之亂數個數");+ B2 ]- z4 P  o
, l# W6 t4 a% ^  ~7 a5 D
        Scanner s=new Scanner(System.in);+ n6 n' N: t: h6 g5 Q1 q
0 s7 H- G$ b) }  I7 {% T, d  b
        //System.out.println(s.nextInt());/ L' ?2 Q+ l' K: P% c
! [' I5 J4 _( r( \- ?; Z4 U, R. H0 n
        int n = s.nextInt();
) @: T* R: ?1 H( N% `: n' a
( ^& T, p7 E& _% q; _, c- X0 D        int ar[]=new int[n];
' v7 D2 {; _6 P. x/ `( [& |
0 `* f* R0 ?* q                for(int i=0;i<n;i++)- `& b( g7 J: G$ M7 t3 S( ?
' T+ ~7 [% a# W1 R; M3 k# v
                {
0 d# m' F6 Z* i1 a* t
; v( X2 r% F5 m  l, t1 q) P5 \                ar[i]=(int)(Math.random()*1000);
$ u) W- X# b0 D0 f2 P% Z
/ ]1 \. e& I8 L3 ^& w+ u                }
* M0 G1 C9 d" s! ^( s* s* R0 I) O3 N6 `& [, I- E- c5 K  b; ^4 {
        Arrays.sort(ar);8 D9 o9 p) X1 {) `' L" B

5 i+ y9 R2 s# q  c                for(int i=0;i<n;i++)
  C0 W: K6 F. P" J1 Z3 M, U, \
- l& z' x# h* _/ K7 ~                {; e$ Q2 r# }. z" l+ h
4 `% G+ R9 t, U$ g9 W/ Q
                System.out.print(ar[i]+"\n")        
" w/ Z1 {+ M; I/ ~2 K
; X3 [( n0 C- W9 ~, D( }               
9 f4 V8 k" X+ A  ^; d0 @; a) Q3 N6 q( t, k$ z
                }6 E' F) q  Y* Y! \' s
( t" M# U( Z( d) H4 ?
        }
* ]/ Y6 B' z  Q; a* k# y5 }9 k! A  g1 k4 X9 a! O9 m7 Z% g; r
}
人平

TOP

返回列表