返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 7 i1 p3 Q: C; O9 N& J
9 m! q! d9 u9 x% I$ f4 c$ q' C% t  ~
程式中可以輸入值
! C8 ?" F! b" c+ j3 v! {7 W
5 F' M% W, v( D$ |# {0 y% `實際寫出 jvd103
$ R/ K) _3 V# L  C- d, h1 p5 G, c. Y% s
使用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 資料函式引入
' y9 E/ V! a$ e% k& Y) l" f) M" p2 H; f, e
import java.util.Arrays ;/ \- C$ D9 k2 r
0 M' y2 @5 @+ z0 N! `1 X: h

( a% P$ ~  g- a: J) [
! f. n8 o7 u( v3 V# k: Bpublic class JVD103{
3 D- d0 Y- }' {
' `; M: l0 L* o/ q1 N; Z7 P  ?  |9 `% c- {: h7 a

; R7 z; Y% _* ]0 P- H        public static void main(String arg[]){7 L" y$ L4 r* U" ]0 D2 t, I8 `% o- P
$ I7 a+ K8 ~& B: z
        , A: [; m' h, n+ K  N1 h' W

' C, ~0 X; M+ |* p& R$ o2 D        3 U7 }5 J( Z( H' _

% ?. p0 L1 C9 I0 T7 H                System.out.println("請輸入欲產生之亂數個數:");
/ X) g- |# ~: t3 L$ G; C; [8 I3 Q7 F8 t# |: q3 y
        
& q# M: f. q- D6 n: v" K2 j+ N& ?  C
2 H4 [# g* l# U- }# x3 G: }7 t0 F                int n = 0;  //輸入要產生亂數個數 並初始化/ c0 G$ s+ t0 N5 O6 b9 _4 e
, i( o' Q7 n9 N8 Y" N5 @& A
                : Z$ n' n6 M3 l
. B4 b7 O2 ^. o( i& j
                //使用到io 一定要加上 try catch
# N; V+ K% @& i/ L, b8 [) t4 p$ \/ M' z6 u. m+ T4 K
                try{6 C1 @' w% \5 C2 A8 z" \

) e, o6 ]- n- d* m, u                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流0 D9 A' ^3 E" b

9 `/ e, Z/ |; s8 F! j8 Y6 _                        BufferedReader br = new BufferedReader(isr); //資料暫存區
, |3 J! ]$ y4 f9 c: R
7 u# Y: D4 ]1 i7 \$ o                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)5 M9 ^, E2 g+ O" R

5 j2 g; W9 L- u" g2 m# D8 r- n                }catch(Exception e){}
5 _  Z( U7 h1 g
5 K* \9 r1 P  ]# @) A9 i                & q  @4 n, G& ^+ v% @( L4 M

+ E# E* N7 c' f2 U5 z3 ~/ r               
) V# b* u) h2 D% Q4 A
+ Z3 k% N' c- T4 g  E9 A                int Num[] = new int[n];//產生n個亂數的變數3 A; ~7 G0 r+ L5 w* A: D; m
; k; J' v5 g) V9 M+ J' X
                % s! g/ r/ |) w% d  H
. `# _( |2 t. f  m9 n
                for(int i=0;i<n;i++){4 Y$ ]1 Z4 G5 @2 i+ [0 ^

" u) t# Y5 _8 Q8 {5 ^; I6 `                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)! h/ y: i1 N, q8 n
/ @1 [- _% Q5 V. Q; P" B
                        //System.out.println(Num[i]);
/ H  g. x2 D, F4 f" Q" Q
0 X( R" L" N4 Z; ?# W0 T  h                }
: `& ?* P( y& ^4 i& n  y& b( B9 k, n" E; V
                Arrays.sort(Num); //排序
1 k( X, p2 n+ L' F' {. L' b4 U) w7 T5 a9 D! ?0 r+ v8 D% N% S
                8 X0 Z" I# N; H5 R4 U2 B8 w
! `. }7 l: [! G) O, z& u9 \7 c; d
                //輸出# Z+ X. L: u* S3 M: X

7 m/ \7 [  H' I8 \                for(int i=0;i<n;i++){
3 Y! m4 D" B3 x# x( X8 R; B4 L9 R1 k' Q! M  E" x$ P
                   System.out.print(Num[i]+"\t");
4 {% U* \. U, ]  n2 C: _9 _: u
, A9 t* _$ A! l: E  {                }
6 m( q; e! R4 d1 Y0 i& T# c6 v% A3 y& c+ v  Z
                : [. q4 l; m  a& ?

% [' m6 C; r5 u        }3 b9 r' a' {1 ?5 X" g

! y4 v9 Y# g$ U5 A7 u3 h) S" q8 {
# h# b% t  H' X6 E) Q
& S2 _' s- k+ J}
人平

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;
# ?: ~0 @" {- v# }: k: O4 t/ E  }
# [$ B) o/ f0 L/ B4 Y& c) Y4 d& M  ?import java.util.Scanner ;) W  n# V9 |; f; {
1 j+ j5 D; a" m3 @* u, L& ^5 y
public class j1036 r2 x7 l# S. R. D

' F0 k' b! A) q2 R# k, R{2 Q# M8 I  C6 X" Q, {, j; H
8 q) p( i, k. T+ ~" J
        public static void main(String[]arg)! f2 r) O2 L& J+ P( n& b

2 Q/ y# D2 q1 w5 `1 S; `7 i        {
# G* i- O! K5 @1 ?
7 `4 ~8 `+ s+ f+ g+ o        System.out.println("請輸入欲產生之亂數個數");
3 C' F, W9 W& o' V: Q# w) K* d- F' s5 G& N% q4 X+ Y
        Scanner s=new Scanner(System.in);5 F, P4 ]. ~% G  d
, o9 s  G% z8 }, B$ d) v# ]  d% i
        //System.out.println(s.nextInt());
& R" L$ V& }% d* p' o" Y
: z" f) |9 w  b1 z. z$ Z9 Y        int n = s.nextInt();
" g" h0 T$ ]+ l4 W
- j6 O2 v' z& W4 X% }3 J        int ar[]=new int[n];7 ~  q1 V' o2 Y: x# y

# r6 }- A3 B. \6 X3 H* q                for(int i=0;i<n;i++)
2 r* L& f, Q# K9 e3 T3 ^' r
- `) Y) D; [, h                {1 a. V( A) R1 N. F8 f

3 K: z9 D, N; C5 K" k( R5 v                ar[i]=(int)(Math.random()*1000);
4 I+ |' [; Z4 N) M* S1 l$ j) V, n* _/ [- o2 X, `; |
                }
6 H5 P0 Z7 P/ g8 {, {5 y
% m8 Y' j; R0 y) m+ Y% x' `        Arrays.sort(ar);6 r9 f  ~4 s# X1 |
3 s$ ^. k( \  b: I3 d
                for(int i=0;i<n;i++)7 H6 |% ~0 L' B$ I5 ?  T

2 K5 ~' M2 x7 B                {
5 t! {; E: j; s" n
7 ]6 e6 n2 |/ |4 H& d9 Q4 X  }3 Y                System.out.print(ar[i]+"\n")        
0 K0 G) Z6 j" }+ C4 P5 X% G0 W$ J8 z) e6 A
               
7 Z; d8 T( q6 _8 D
# M' L3 c  }7 W; v                }9 F' g$ ^" }# x. z
9 ~/ g/ _! h" I8 H" z& p2 W7 d" w
        }
/ {$ e' B# E  l
2 }6 L: u. K8 @0 U0 K}
人平

TOP

返回列表