PDA

View Full Version : phai lam the nao day



longkt
10-04-2003, 17:05
toi lam mot ct nho nho :

nhap 3 so tu ban phim
roi hien ket qua la ba gia tri vua nhap phai lam the nao day

voi mot so thi khong co van de nhung ba so minh chua biet lam the nao ca


ai biet chi dum voi

Yulaw
30-11-2003, 20:29
Ban muon nhap ra sao?
Neu nhu parse vao arg cua main thi chi viec doc ra thoi
Con neu nhu lay ban InputStream thi ban cu cho nhap 3 so thi du nhe
Nhap 3 so : a b c
a,b,c la so nguoi dung nhap sau do dung StringTokenizer de tach ra thanh 3 so

moibelgal
30-11-2003, 21:40
Thật ra đây là một phần rất đơn giản của java .
Bạn có thể xem code :

import java.io.*;
import java.util.*;

class readThreeNumbers{

void readInts() throw***ception,NumberFormatException{
InputStreamReader isr=new InputStreamReader(syatem.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
StringTokenizer st=new StringTokenizer(s," ");
int c=0;
while (st.hasMoreElements()){
c++;
if (c==1) n1=Integer.parseInt(st.nextToken());
else if (c==2) n2=Integer.parseInt(st.nextToken());
else if (c==3) n3=Integer.parseInt(st.nextToken());
}
}

public static void main(String s[]){
readThreeNumbers cl = new readThreeNumbers();
try{ System.out.println("Nhap 3 so : ");
cl.readInts();
}catch (numberFormatException e){}
System.out.println("Do la 3 so : "+b.n1+" "+b.n2+" "+b.n3);
}
Bạn có thể thêm yêu cầu cho bài này . Chẳng hạn xét xem 3 số nguyên vừa nhập có phải là 3 cạnh 1 tam giác hay không , hay trong 3 số thì số nào là số nguyên tố lớn nhất v.v...