Board logo

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

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
9 o0 ]/ ~2 z0 W0 T3 F
* e. q) W( @; Z/ U程式中可以輸入值
3 o( h8 T5 o7 Y! g* _8 {! a
% M! A: Z; E5 s9 A  H/ h  x實際寫出 jvd103
) j! v  ^+ k: ?0 K3 H3 }0 M& G; Z/ I; `6 B
使用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 資料函式引入: u0 b) R5 _/ z! i7 l5 `

8 a4 L# p1 ^" Gimport java.util.Arrays ;
) k7 c2 l; I$ ~$ k9 T' e  _+ X5 n
  p. Q( A5 q& s4 ]$ y. K& _& u$ S3 ^0 q& O6 k! t2 o: D  M; `/ ?3 C

1 @/ r$ }# X3 q. k) qpublic class JVD103{& b# p( i9 K6 }( y. f; L

& Q' |3 R( c% i/ ], Y% _
7 H  a$ t% T. {
; F. s4 s; k, Z  ]0 E        public static void main(String arg[]){5 R( h1 d: j- f
: R) J& U: @2 g# z! }
        
+ C; A1 b4 }" x8 t/ S* Z( w& B
, Q$ I9 U/ F7 {8 I) r: ]. ^- C$ |        0 Z3 r7 i- {3 z. H6 U

- G* m# r+ _' ~" |5 `+ Z# I# `+ l4 u                System.out.println("請輸入欲產生之亂數個數:");6 U. {1 s+ c; z* o9 {

$ W: Y; P- @$ _3 Y        2 c$ t6 g; _$ [$ Z/ H

: `2 U8 Z# `7 h7 Y/ [                int n = 0;  //輸入要產生亂數個數 並初始化$ R2 E. j1 u& k: ~

4 {- R2 ~, }) i: |# v1 k# Y               
' K- R9 X  j6 n; x- E6 T1 R# x' W9 s- u( R' [; W
                //使用到io 一定要加上 try catch
* K  n" ~0 w. w. \" T6 O$ T( F7 A/ A* _4 B
                try{
) P6 L  [& N) }% @' D) Y5 h, Q& ~2 U+ [2 o2 V5 \
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
. t4 n! r, v1 m* B
' C% C& Y* ~4 }/ R( x                        BufferedReader br = new BufferedReader(isr); //資料暫存區
4 Z+ ]( t3 f2 |
: Y$ Y2 |- z. F1 S* E                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)9 m; F1 G- ?7 q6 I
1 a# K1 x8 Q1 {
                }catch(Exception e){}
8 g4 J) w7 R1 ?# h
3 I/ ^+ K: A$ C5 N. I/ S, p& p) O               
8 ?7 j! U, @7 R) P5 U0 E
& z3 b! H0 T- D4 Y. l$ q8 K! k# U4 A2 W                ) c4 F2 L+ c8 n. A

  E/ {; b1 k/ `" k. U. T                int Num[] = new int[n];//產生n個亂數的變數
# f6 Q: p  `! G" c5 p2 ?, o0 _  X# x2 R: z
               
! q. U# F; I7 z
( l1 S8 m# c* O                for(int i=0;i<n;i++){
6 j- |$ B/ K& U6 }! x1 ?: G: R; X
5 D- P8 M, a# `" D4 p9 Y2 L                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int); F0 M! B* j; e8 `
5 |: ~; K$ {$ L) n( V2 [
                        //System.out.println(Num[i]);) w5 i7 a  t: z; Q
6 B; t9 W! J" t0 z" _5 o' Y: j
                }
8 v$ P; a7 H! y  C; ~3 q& E
5 S4 Y5 t* A% T# K; W                Arrays.sort(Num); //排序" r: i) W' y9 }% w) l* Y/ L

6 b3 ?  h  ~" B  i/ a" n3 q                $ A0 v% @7 S* c

, G3 F$ A7 ~$ u( G3 l. Q                //輸出
- q) }, U! N; ~, I0 ~4 m
+ r1 Q5 N) V# ?1 f5 E/ ?                for(int i=0;i<n;i++){8 N. d" |( {3 O% {! ^! o5 O

/ ^9 E4 L0 b1 o( M1 }7 ~4 B( J                   System.out.print(Num[i]+"\t");2 ^2 @0 {5 f5 J. b8 q

+ j* G: u% i6 F) k                }
2 |$ a! q' _$ G$ P0 t8 Y9 u( O2 u" P" K
               
  I$ [0 t# y( H$ A
3 @6 w- O8 f. d# B5 Z& F& {0 `        }* g) K" I$ c& z( @# d$ b: S6 D

# m1 n. M7 _& _, b0 X3 O5 u1 k( p8 y! d/ m% {  z
  |- O5 Y. G$ d8 }
}
作者: 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;: T# m4 ^! r1 C- v) g" @$ [
3 R, l+ F3 a' i: z$ \
import java.util.Scanner ;9 K$ u9 U& G- t' [
9 |( v- d: k1 B; D: g  f$ |0 {
public class j1035 h$ v8 [9 E7 d4 P% p- A( G% ^
  t' F5 E8 d9 J% K$ u9 Q' K: `
{
0 o8 e0 G; N+ Q" \. ]. q" ^9 n7 z7 `( W) p% q! M& [& c
        public static void main(String[]arg)9 M8 I# B  l" n
; \7 U5 F: W8 z1 M2 v4 W
        {" Z' Z: G2 I) r' {! Z' o

& z. G4 A) Q5 x7 C$ q7 E. ]        System.out.println("請輸入欲產生之亂數個數");
' m0 f3 J1 X- ^0 w4 `) }( e! q/ j
. c6 X* m+ k1 T  p, Z        Scanner s=new Scanner(System.in);
* ]+ F( ]% W: x# V7 l+ V# [% P- ~' k) h" |9 y5 G6 }) R0 N
        //System.out.println(s.nextInt());
! _3 m& w: D% t$ {% s7 \  n
. ~- c( `/ _( o3 q% o' ?$ I        int n = s.nextInt();
+ e2 Q, z" P6 w7 a% P; G) v! b( E/ G( L% V( J
        int ar[]=new int[n];
; F2 b7 H$ J9 S' U/ o# c: g- h/ G& x+ _6 G% ~5 B. B
                for(int i=0;i<n;i++)
0 k1 S7 I  ~% E# {) {3 T8 `. [1 ^
" ^4 T$ s: ?6 e7 c                {/ Y$ K; C" i+ e9 o7 ^: o
0 l: t. H% W% Q4 A% \' ^; e' r
                ar[i]=(int)(Math.random()*1000);6 Z9 l" D( T% @" B( L

8 O, m7 P6 o% Q! N% N$ ~                }
0 S9 R/ U( l1 B1 t. ^8 u4 Q- ^+ h" _9 i- i2 B
        Arrays.sort(ar);" s5 S% X$ k/ {( x# \) t

; \8 y: O6 R1 L: Q1 q( p                for(int i=0;i<n;i++)$ k8 M2 \8 c) o. @" o9 p6 m
+ Y; j% `- e0 o& n2 A7 T% g
                {
) S2 Y/ _5 m& i) r' L7 L) ?' Y* y: p1 {: o
                System.out.print(ar[i]+"\n")        . U- b, V  l1 D  v

- V. ]5 p" o% R- u+ {               
" X# U  a. Q; v- \& K* \2 \' O/ |4 |, I' V7 e# T0 b; z! R+ A. _
                }7 D3 Q& P) O1 {- g% p
! P+ G+ \% b6 G" n; {+ k6 O8 v8 e
        }
6 t7 J' Q) W1 @9 b
! f6 F0 l5 h1 b9 y9 p}




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