Board logo

標題: 1217 使用者輸入值(實作jvd103) [打印本頁]

作者: b790113g    時間: 2011-12-17 10:47     標題: 1217 使用者輸入值(實作jvd103)

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 / U/ H6 |# \0 R( i4 H& a7 Q  ?% l

: d  K( V2 Y5 H  b3 V. R程式中可以輸入值
# R: ^) @8 j3 p# N% H+ @# p2 i( x+ U) p1 S/ Y- S- i
實際寫出 jvd103
' _8 a& [+ @: ]: G/ W7 L# a: r1 L0 s1 [  ^
使用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. }
複製代碼

作者: eric5802    時間: 2011-12-17 11:37

import java.io.* ; // input output 資料函式引入
- u; R& P& q( f  v9 d: ]
% @8 Q1 m* E7 ]9 B" O7 \6 W3 gimport java.util.Arrays ;
, }0 r0 V, L1 n( E* P3 u
; B5 T! j; q, @4 v9 c2 e
. r' ?$ @$ z; f7 O" q! }/ c; _4 R7 _" O3 l, e6 n- \
public class JVD103{
! a$ d) [) P- Q/ K  i
0 L" [* I$ e& ^1 W: {+ v+ H: |3 v  e
  L& S4 {! M8 d4 I, k. f& {
0 Y7 s: Z1 O( B. x4 U4 K        public static void main(String arg[]){
- c8 \1 v7 h5 ?6 E
3 ?0 T5 T; o  e% L- |  J        
/ \! t( X( h1 ~6 V) B' L2 y
- t0 Z) c7 F( R1 w# [7 m        . m# U' _8 A0 O: w$ A
5 m9 g; x3 \7 K( K5 Q- H5 n
                System.out.println("請輸入欲產生之亂數個數:");, ]: W9 l3 I$ C$ z! \
+ c  F$ N; `' U2 t- J5 r0 b
        
0 y. V* ]* n( R& b6 i) g/ f" D( Y
0 N! n+ r0 r" ^, J7 n                int n = 0;  //輸入要產生亂數個數 並初始化$ p1 U% k1 m1 n4 }; s, k% H% Q9 J
, p' a' B) Y) l6 N2 _
                4 @8 Q( U+ @4 q: t) U# j% f

/ _; T- S5 M6 a* g: }: C                //使用到io 一定要加上 try catch
: `/ L; t. s* M  p9 t& I0 K1 W* G# ~2 i( p, [
                try{
: q! Y9 J2 x; ?" J$ A* U, N8 y
1 U5 f6 q* a2 X& r" t. N9 @                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流% q: ^4 G8 ?5 {' d! e

" O6 l) [1 I3 x9 S                        BufferedReader br = new BufferedReader(isr); //資料暫存區* [  ^, S% w7 a$ [1 ?, b3 T
3 F" X, K7 ~! ]  |! Q0 w
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
3 n# {/ V2 b, ~  P. C3 k0 Q
$ S+ [( O# ^8 _, l# z/ U                }catch(Exception e){}
+ @& [9 x2 {6 }/ x5 a+ C: o$ C1 X  m& Q% f
                3 ]0 f* i/ }0 `: a2 d' {6 h. C2 F+ N

  r9 P$ B/ j5 L! H) v# g. D$ i                4 a( U. A/ s  k( K

2 N1 r6 m* R( Y9 ~( _                int Num[] = new int[n];//產生n個亂數的變數
( C2 ]/ G- G! g( @1 ?9 I. H8 ~! \0 v
                / |0 K. o% e1 L
+ o! X! c) W, g/ u5 I7 v: Y
                for(int i=0;i<n;i++){
7 y; Y5 {, S6 b$ S  u, T4 f1 u: B6 W8 e
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
) C2 c! y- F$ B, |' W: a& K) |2 K! v% f  H; w4 \
                        //System.out.println(Num[i]);1 F% c  P  {& v& }8 ?' A0 a: ]0 }% }
3 u; @! G3 J5 F/ n6 F/ n+ a* L7 A1 s
                }) Y# }6 W4 E/ z# M0 [. m

8 F6 z% T' X( a                Arrays.sort(Num); //排序  `* Z4 l1 K% t, ]

5 J0 u, P' ~; v( |9 k               
: k1 Q8 \- G0 ^7 }4 n5 M, V7 e5 _1 B& P# s2 M& T
                //輸出3 O4 \3 m) r0 D% e. H: _

5 u  b7 s( i9 w- n" O8 h# D9 X                for(int i=0;i<n;i++){, |  ?: E6 p2 Q! c' M* \7 ^5 O+ l

; v. V# {! D. G/ K" H6 E, J                   System.out.print(Num[i]+"\t");8 ^  ~3 L- r- h/ \( O+ T: ^) g

: C; s1 F) V, w                }, y+ \* ~" w' r  {

& W. n, f$ e( N3 g5 _0 W               
5 p4 H4 u4 o0 s" S, O: a1 z% w4 l* d5 o. V- T5 x3 b# F
        }4 V# x) t% C3 t5 h3 T

) O8 n9 i. @4 P
$ E% [7 {! X1 z0 `2 n+ e' k. a: i" H
/ [$ b! Y4 m4 t9 Z- t}
作者: kim    時間: 2011-12-17 11:46

  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. }
複製代碼

作者: johnson    時間: 2011-12-31 09:57

  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. }
複製代碼

作者: kim    時間: 2011-12-31 09:57

  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. }
複製代碼

作者: TOM    時間: 2011-12-31 09:59

  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. }
複製代碼

作者: eric5802    時間: 2011-12-31 10:00

  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. }
複製代碼

作者: may    時間: 2011-12-31 10:09

  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. }
複製代碼

作者: eric5802    時間: 2011-12-31 10:20

import java.util.Arrays;
# a3 F+ R7 ~0 @: b; A, n  Q0 F8 @  ^3 n& A0 t6 w! V- B
import java.util.Scanner ;
4 o( _8 w) B3 l6 _3 ^! _* G" @
; S3 Y* S' f1 o7 s  mpublic class j103; M/ I) c/ W4 s; n* ]( o9 A' h
, @- q: m  w1 p
{
$ N5 l( E" t: Y7 U. }* r( R8 w8 i9 f+ Q( E5 P0 B4 V; t
        public static void main(String[]arg)
( K2 \0 V8 n# i
' ?- v. N0 ~& F, v: U! a: c        {/ Q4 ^+ o- F( [6 a4 Z7 H

( V& R: U0 Z& G! h0 m/ X        System.out.println("請輸入欲產生之亂數個數");
3 F. O0 q6 _) T' J  }
. l1 n( d7 `8 l. M5 M3 q  K        Scanner s=new Scanner(System.in);$ _$ N1 ], @. o( H7 N
3 M9 R8 S/ q) g0 f1 |2 r
        //System.out.println(s.nextInt());
2 B& S2 u+ [, M' \! e, \2 @
- O0 X1 ?% ?; @8 J2 d! l: u# F        int n = s.nextInt();
! r+ l% v' z3 F6 p0 ^1 X2 e7 V- }) D! {5 A( D
        int ar[]=new int[n];0 w( M9 I3 {  \
. N! a6 o: i+ c: E% p
                for(int i=0;i<n;i++)& |! O, O- h% U/ I) h3 p
4 Q. |1 `* A/ P0 H+ C
                {
& Y2 X% x! p5 ^% Z' P& m
- k) ~5 L! u' `) g5 v& P- I                ar[i]=(int)(Math.random()*1000);
, S- M0 z# W: b0 ~' `2 t6 G$ ^1 o0 J! u2 H
                }" y0 v2 F+ B* t$ R" [3 x; S3 Y
6 a. N% L+ |' ^
        Arrays.sort(ar);; x+ o& g4 i. J% S

/ y+ T8 s- Z6 J6 D. `6 G7 m                for(int i=0;i<n;i++)
' N+ |% X3 C. O' ^6 R, ~$ B7 r' ]2 ~8 x4 X: ?! j
                {9 ^6 u( ]. C% ]( f' |( s# a: `

. u) l& e4 c- W/ E* |3 Z! j                System.out.print(ar[i]+"\n")        
  J1 i/ c9 S: J+ q
  j0 K7 m/ x7 M$ L0 X5 K5 w/ `                3 t$ E5 C5 {  D8 s7 b
& w! V+ F+ [+ H' W% e: q
                }2 h7 o& V% N6 C! M: H& }8 v
0 t$ |' ^9 r. s# ~- O4 n/ u
        }: p2 Z  A. H& f* M) A6 l1 k
9 i) {4 v# n" {7 a9 \8 Z
}




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2