標題:
1217 使用者輸入值(實作jvd103)
[打印本頁]
作者:
b790113g
時間:
2011-12-17 10:47
標題:
1217 使用者輸入值(實作jvd103)
本帖最後由 b790113g 於 2011-12-31 09:54 編輯
! f: ~0 b w2 E0 n6 y1 k
! [0 `: a) g$ B0 ^
程式中可以輸入值
2 K9 I9 Y, p+ P9 E
$ t( D# f4 x5 Z3 a& o3 M; h
實際寫出 jvd103
6 _: u4 J' i, u; z4 V$ l" W. n
8 n# w# Y% P3 d5 R
使用io一定要使用 try catch
import java.io.* ; // input output 資料函式引入
import java.util.Arrays ;
public class JVD103{
public static void main(String arg[]){
System.out.println("請輸入欲產生之亂數個數:");
int n = 0; //輸入要產生亂數個數 並初始化
//使用到io 一定要加上 try catch
try{
InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流
BufferedReader br = new BufferedReader(isr); //資料暫存區
n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)
}catch(Exception e){}
int Num[] = new int[n];//產生n個亂數的變數
for(int i=0;i<n;i++){
Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
//System.out.println(Num[i]);
}
Arrays.sort(Num); //排序
//輸出
for(int i=0;i<n;i++){
System.out.print(Num[i]+"\t");
}
}
}
複製代碼
import java.util.Scanner; //輸出入
import java.util.Arrays; //陣列
public class jva103{
public static void main(String args[]){
System.out.println("請輸入欲產生之亂數個數:");
Scanner s = new Scanner(System.in);
//System.out.println(s.nextInt());
int n = s.nextInt();
int ar[] = new int[n];
//產生亂數
for(int i=0;i<n;i++){
ar[i] = (int)(Math.random()*1000) ;
//System.out.println(ar[i]);
}
Arrays.sort(ar);
for(int i=0;i<n;i++){
System.out.print(ar[i]+"\t");
}
}
}
複製代碼
作者:
eric5802
時間:
2011-12-17 11:37
import java.io.* ; // input output 資料函式引入
" v" `( _0 c, m$ R- N
8 A+ m* q2 f3 ?
import java.util.Arrays ;
5 Q c, E% k) q5 Z1 n
( ^$ N4 |9 ^+ P' z+ Q
( Y5 r! C! G. l# q2 m
/ I- Q, R. C8 e- `6 Y; \6 Q. t
public class JVD103{
( I* a1 D2 L6 J; T, A- S
- T, k! k. o+ ?6 {* T
6 E3 C4 o3 L+ a6 ?2 ]
$ I }0 i9 m. B
public static void main(String arg[]){
3 H h( @# G: c. _: y1 c6 D
* ~% k x2 u* W0 A: M$ G; J
( R5 o, d) ?& B8 Y- U4 n
% `6 c( [2 |9 r8 \( P4 U. w
6 w, V. q; k- D# U+ W( r7 K
1 A# |# z R8 t7 d
System.out.println("請輸入欲產生之亂數個數:");
: V1 F) h0 [5 G3 r, F" ]/ i3 n9 B, A
% o5 Z. R& G8 U. P; O% Z
* g/ }! i, J# R% _, m& N3 ?
2 V. q/ a. S" S& s! w2 F; }
int n = 0; //輸入要產生亂數個數 並初始化
0 d; j2 q5 |0 e+ U N8 q& D+ m9 h
6 O/ {+ I3 E* U! _# l6 U
& P& C, ~" H6 z2 e1 o
1 S& d# d; s# D) f
//使用到io 一定要加上 try catch
; E- x& e( C1 h# W( C3 }
3 g2 h5 x1 f. M8 q8 C- s
try{
$ x: f! T7 d8 x
" z1 q: r9 [( r
InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流
! {" M( z" j! c7 E3 X; Z; z
& n. ]6 n& ~ h
BufferedReader br = new BufferedReader(isr); //資料暫存區
- K, o7 ^8 e1 m
; v( D+ c( t8 p$ ?9 n' x
n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)
4 A9 x, U( Y5 d, k9 Z8 [8 v
% \ R! v" |7 F% k1 k
}catch(Exception e){}
$ m, C5 `" d0 X# f
- a: O/ k. `0 U- I3 I V" b4 K# A1 I( Y# i
% a [' y+ o# N s; ?
. v- b2 y1 b4 H3 s* g: P( n
, Y& v9 t3 S- l& }7 O
1 C& F2 _) j' q! b
int Num[] = new int[n];//產生n個亂數的變數
# O( d; J7 Q$ i
) @& u$ k- s" \. s
1 M# W' q7 E4 c* I/ }
; a8 O7 W( t) _1 P& A+ h2 z
for(int i=0;i<n;i++){
4 t& T3 k7 l; W. B
, z, z+ x: {/ k0 s, U
Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
* b) R, E/ }5 G& F" J) S
, l; |2 P3 M4 m( N" t+ `
//System.out.println(Num[i]);
0 {+ a& E- t4 r* v8 M
* Y F6 z5 \ [1 h6 [* N) c
}
5 l1 B- |9 Q! E& H9 z+ \
) A; D) {6 F9 A) I6 b
Arrays.sort(Num); //排序
' g* J0 y7 J/ U# g. C
! y: `& c# Q! B, [) k8 z+ B
; h) |1 Q$ {; J) P& E O8 [, @
/ }' ~3 m) c: b
//輸出
" r3 G$ d4 c! @5 A" }
& P) o# I+ E4 k$ [# K, f2 r
for(int i=0;i<n;i++){
4 }) U: p: ^3 P* e3 r' H
/ P" ?& q2 l( R6 M: j( B& u% q2 t
System.out.print(Num[i]+"\t");
% C3 y: E3 B* T; o& `) ^6 T) ]
' q2 {6 H S+ p3 |' m& m
}
( h5 N# J1 H5 U8 D( g: b! o. q
- Q6 E; V( M% F& F5 j
' }4 K5 d5 k3 _" L/ i5 D0 \
7 R4 k3 _; p1 Y' L0 }7 M& x( i
}
7 ]5 e' y: F: y( h
4 `# ~+ I* @0 @
. ~8 ?3 D$ s- X9 |- G& I0 I
' t; D% L5 |* @9 @- O' n
}
作者:
kim
時間:
2011-12-17 11:46
import java.io.*; //input output 資料涵式引入
import java.util.Arrays;
public class JVD103{
public static void main(String arg[]){
System.out.println("請輸入欲產生之亂數個數");
int n=0;
try{
InputStreamReader isr=new InputStreamReader(System.in); //輸入資料流
BufferedReader br=new BufferedReader(isr); //資料暫存區
n=Integer.parseInt(br.readLine ());
}catch(Exception e){}
int Num[]=new int[n];
for(int i=0;i<n;i++){
Num[i]=(int)(Math.random()*1000);
System.out.println(Num[i]);
}
Arrays.sort(Num);
for(int i=0;i<n;i++){
System.out.print(Num[i]+"\t");
}
}
}
複製代碼
作者:
johnson
時間:
2011-12-31 09:57
import java.util.Scanner;
import java.util.Arrays;
public class j103
{
public static void main(String[]args)
{
System.out.println("請輸入欲產生之亂數個數:");
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=(int)(Math.random()*1000);
}
Arrays.sort(ar);
for(int i=0;i<n;i++)
{
System.out.println(ar[i]+"\t");
}
}
}
複製代碼
作者:
kim
時間:
2011-12-31 09:57
import java.util.Scanner;
import java.util.Arrays;
public class j103
{
public static void main(String arg[])
{
System.out.println("請輸入欲產生之亂數個數:");
Scanner s=new Scanner(System.in);
// System.out.println(s.nextInt());
int n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=(int)(Math.random()*1000);
// System.out.println(ar[i]);
}
Arrays.sort(ar);
for(int i=0;i<n;i++)
{
System.out.println(ar[i]+"\t");
}
}
}
複製代碼
作者:
TOM
時間:
2011-12-31 09:59
import java.util.Arrays;
import java.util.Scanner ;
public class j103
{
public static void main(String[]arg)
{
System.out.println("請輸入欲產生之亂數個數");
Scanner s=new Scanner(System.in);
//System.out.println(s.nextInt());
int n = s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=(int)(Math.random()*1000);
}
Arrays.sort(ar);
for(int i=0;i<n;i++)
{
System.out.print(ar[i]+"\n")
}
}
}
複製代碼
作者:
eric5802
時間:
2011-12-31 10:00
import java.io.*; //input output 資料涵式引入
import java.util.Arrays;
public class JVD103{
public static void main(String arg[]){
System.out.println("請輸入欲產生之亂數個數");
int n=0;
try{
InputStreamReader isr=new InputStreamReader(System.in); //輸入資料流
BufferedReader br=new BufferedReader(isr); //資料暫存區
n=Integer.parseInt(br.readLine ());
}catch(Exception e){}
int Num[]=new int[n];
for(int i=0;i<n;i++){
Num[i]=(int)(Math.random()*1000);
System.out.println(Num[i]);
}
Arrays.sort(Num);
for(int i=0;i<n;i++){
System.out.print(Num[i]+"\t");
}
}
}
複製代碼
作者:
may
時間:
2011-12-31 10:09
import java.util.Scanner;
import java.util.Arrays;
public class jva103{
public static void main(String arg[]){
System.out.println("請輸入欲產生之亂數個數:");
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int ar[] = new int[n];
for(int i=0;i<n;i++){
ar[i]=(int)(Math.random()*1000);
//system.out.println(ar(i);
}
Arrays.sort(ar);
for(int i=0;i<n;i++){
System.out.print(ar[i]+"\t");
}
}
}
複製代碼
作者:
eric5802
時間:
2011-12-31 10:20
import java.util.Arrays;
3 }1 x6 L) e- _" H) D
* d0 p! _; k! v8 F7 h9 @4 o
import java.util.Scanner ;
$ s, h5 B5 n \! t! s) Z
8 G( E1 S: W! ]/ \- b' i
public class j103
+ H" R! z" [/ D: _ d2 T
: V; a" a# P3 b. l3 f
{
$ e0 k2 f2 i2 _0 Q- {0 N
; F7 s3 W) Y2 z7 [* [% |
public static void main(String[]arg)
r6 B) `( r1 w* [* j4 H
/ x' ~1 k# \9 l6 O: H4 p5 c: R
{
3 P% J1 D, ? n; q3 J! S6 w2 C
, m, D+ f" Z# Z6 C8 j
System.out.println("請輸入欲產生之亂數個數");
. x! p1 |* x1 M! @6 q
0 w5 _% x$ G1 t/ t$ Q- K$ O5 N \
Scanner s=new Scanner(System.in);
v* k% Y' ]. ]+ x+ u3 Z) H
# n0 Q$ }7 b, }; G: ?$ s
//System.out.println(s.nextInt());
1 c+ z. J; q0 I* `# @% t
# W/ V+ c% D. ^3 `1 E8 R
int n = s.nextInt();
# V! H6 R/ d5 Y/ k
0 l6 S9 w6 p# @. Y4 a& C" l9 Q) F* Y
int ar[]=new int[n];
c$ k$ {, H' X+ J3 g ~ H$ T
0 }4 V8 Z Q7 e% a0 S" e
for(int i=0;i<n;i++)
8 S2 i8 u- `# O U7 J6 k( F; T
i0 W/ B6 x' Z8 w
{
8 I5 L; W$ D% u: o, k) R4 p
4 r# m8 a* c& X! x6 Y: W' X3 n
ar[i]=(int)(Math.random()*1000);
3 G3 y6 @- Q" j$ H% b7 b
+ K f9 `8 i7 N6 P m) R, z. A" s
}
. f; F4 `4 h1 h4 H
# O4 C% G3 {3 `" ~" e
Arrays.sort(ar);
! l/ z0 C. d% ~# p' E; a+ d9 Z! T
0 i+ A: K) `% T7 P% I
for(int i=0;i<n;i++)
, b/ e/ ` Y; k4 A" A4 R
% h* w! L) l% d0 @% h$ z% R
{
& `" L f' o9 D2 N6 d, n
* `) ?% C5 ]! E* y1 e( o
System.out.print(ar[i]+"\n")
}% e; y0 H2 b9 E, E8 y
' v) t* D7 i6 P
8 c: d3 n- p9 f! N$ L( d/ O3 H* y
) H* X: @0 c# I$ b3 P
}
7 g3 L, T8 O' p. q, J
. d, N6 G b' ^: J* R3 G5 Z4 B
}
( s3 u6 {; W7 G4 i7 d+ |& w
. ~# p3 v8 ?) Y1 Y ~
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2