7 bài tập về java Have Full
5 posters
Trang 1 trong tổng số 1 trang
7 bài tập về java Have Full
Bài 1 : Viết chương trình hiển thị ra màn hình câu : " Hello Java"
Bài 2 : Viết chương trình nhập vào 1 chuỗi ký tự. Đổi thành chữ Hoa và in ra màn hình.
tố hay không và thông báo ra màn hình.
Cách 1:
Bài 6 : Đọc 1 file text và hiển thị ra màn hình nội dung file đó.
Cách 1:
đến 100. Quan sát kết quả và nhận xét.
Chúc anh em làm bài tốt
- Code:
public class Lesson1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello Java!");
}
}
Bài 2 : Viết chương trình nhập vào 1 chuỗi ký tự. Đổi thành chữ Hoa và in ra màn hình.
- Code:
import java.util.Scanner;
public class Lesson2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("Nhập vào 1 chuỗi ký tự>>");
String s = input.nextLine();
System.out.println("In hoa là: "+ s.toUpperCase());
}
}
tố hay không và thông báo ra màn hình.
- Code:
import java.util.Scanner;
public class Lesson3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("Nhập vào số nguyên>>");
int n = input.nextInt();
boolean a = true;
if ((n==1) ||(n==0)) a = false;
for(int i =2; i<n; i++)
{
if(n%i ==0) a = false;
}
if(a==true) System.out.println(n + " là số nguyên tố");
else System.out.println(n + " không là số nguyên tố");
}
}
- Code:
import java.util.Scanner;
public class Lesson4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("Nhập vào số nguyên n:= ");
int n = input.nextInt();
int s =0;
for(int i =1; i<=n; i++)
{
s=s+i;
}
System.out.println("Tổng từ 1 đến " +n + " là: "+s);
}
}
Cách 1:
- Code:
import java.util.Scanner;
public class Lesson5 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Nhập vào 1 dãy số thực gồm n số");
System.out.print("n:= ");
int n = input.nextInt();
float a[] = new float[100];
float s =0;
for(int i =0; i<n; i++)
{
System.out.print("a["+ (i+1) +"]:= ");
a[i] = input.nextFloat();
if(a[i]>0) s=s+a[i];
}
System.out.println("Tổng số thực dương là: "+s);
}
}
- Code:
import java.util.Scanner;
public class Lesson5v2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Chương trình tính tổng dãy số thực dương nhập từ bàn phím");
System.out.println("Lưu ý nhập 0 để dừng!");
float s =0;
float n =0;
do
{
System.out.print("Nhập số: ");
n = input.nextFloat();
if(n>0) s = s+n;
}while(n!=0);
System.out.println("Tổng số thực dương là: "+s);
}
}
Bài 6 : Đọc 1 file text và hiển thị ra màn hình nội dung file đó.
Cách 1:
- Code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Lesson6 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
FileInputStream fin = new FileInputStream("D:/input.txt");
Scanner input = new Scanner(fin);
while(input.hasNext())
{
String s = input.nextLine();
System.out.println(s);
}
input.close();
fin.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Không tìm thấy file dữ liệu!");
}
}
}
- Code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Lesson6v2 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner input1 = new Scanner(System.in);
System.out.print("Nhập đường dẫn pacth: ");
String s = input1.nextLine();
try {
FileInputStream fin = new FileInputStream(s);
Scanner input = new Scanner(fin);
while(input.hasNext())
{
String s2 = input.nextLine();
System.out.println(s2);
}
input.close();
fin.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Không tìm thấy file dữ liệu!");
}
// TODO Auto-generated method stub
}
}
đến 100. Quan sát kết quả và nhận xét.
- Code:
public class Lesson7 extends Thread{
String name;
public Lesson7(String ten)
{
name = ten;
System.out.println("Thread " + name + " được khởi tạo!");
}
public void run()
{
for(int i =1; i<=100; i++)
{
System.out.println(name + "---" + i);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Lesson7 t1 = new Lesson7("Thread1");
Lesson7 t2 = new Lesson7("Thread2");
Lesson7 t3 = new Lesson7("Thread3");
t1.start(); t2.start(); t3.start();
System.out.println("Độ ưu tiên của luồng Thread");
System.out.println("Ưu tiên của Thread1: " + t1.getPriority());
System.out.println("Ưu tiên của Thread2: " + t2.getPriority());
System.out.println("Ưu tiên của Thread3: " + t3.getPriority());
//System.out.println("Đặt độ ưu tiên của Thread");
//t1.setPriority(Lesson7.NORM_PRIORITY);
//t2.setPriority(Lesson7.MIN_PRIORITY);
//t3.setPriority(Lesson7.MAX_PRIORITY);
//t1.start(); t2.start(); t3.start();
}
}
Chúc anh em làm bài tốt
Re: 7 bài tập về java Have Full
Thank phát.
Bác admin có bài gì ống ống thầy làm hồi sáng post lên nha (bài phương trình bậc 1).
Bác admin có bài gì ống ống thầy làm hồi sáng post lên nha (bài phương trình bậc 1).
shippou777- Posts : 460
Thanked : 8
11/10/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
Không, có bài tự làm nhưng không chạy, bài của Thầy Trọng giữ rồi chưa thấy Post. Nếu muôn xem bài tôi thì nó đây. Đã fix lỗi
Class Server:
Class Server:
- Code:
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class Server extends Thread{
/**
* @param args
*/
int a,b;
int kq;
float x;
PipedInputStream inputS;
PipedOutputStream outputS;
Scanner input;
PrintWriter write;
Server()
{}
Server(PipedInputStream Sinput, PipedOutputStream Soutput)
{
this.inputS = Sinput;
this.outputS = Soutput;
System.out.println("Server được khởi động... ");
}
public void send()
{
write = new PrintWriter(this.outputS);
write.println(kq+" "+x);
write.flush();
}
public void recived()
{
input = new Scanner(inputS);
a = input.nextInt();
b = input.nextInt();
}
public void prosing()
{
if (a==0)
{
if (b==0) { kq = -1; x=0; }
else { kq = 0; x=0; }
}
else { kq = 1; x = -b/a; }
}
public void run()
{
while(true)
{
recived();
prosing();
send();
}
}
}
- Code:
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class Client extends Thread{
int a,b;
int kq;
float x;
PipedInputStream inputC;
PipedOutputStream outputC;
Scanner input;
PrintWriter write;
/**
* @param args
*/
public Client()
{}
public Client(PipedInputStream Cinput, PipedOutputStream Coutput)
{
this.inputC = Cinput;
this.outputC = Coutput;
System.out.println("Client được khởi động... ");
}
public void inputab()
{
input = new Scanner(System.in);
write = new PrintWriter(System.out);
write.println("Chương trình giải phương trình bậc nhất!");
write.print("a:= ");
write.flush();
a = input.nextInt();
write.print("b:= ");
write.flush();
b = input.nextInt();
}
public void send()
{
write = new PrintWriter(this.outputC);
write.println(a+" "+b);
write.flush();
}
public void look()
{
if(kq==-1) System.out.println("Phương trình vô nghiệm");
if(kq==0) System.out.println("Phương trình có vô số nghiệm!");
if(kq==1) System.out.println("Phương có nghiệm x:= "+x);
}
public void recived()
{
input = new Scanner(inputC);
kq = input.nextInt();
x = input.nextFloat();
}
public void run()
{
while(true)
{
inputab();
send();
recived();
look();
}
}
}
- Code:
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PipedInputStream inputS = new PipedInputStream();
PipedOutputStream outputS = new PipedOutputStream();
PipedInputStream inputC =new PipedInputStream();
PipedOutputStream outputC = new PipedOutputStream();
try {
inputS.connect(outputC);
outputS.connect(inputC);
Server S = new Server(inputS, outputS);
Client C = new Client(inputC, outputC);
C.start();
S.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Re: 7 bài tập về java Have Full
nhạc nghe ớn quá
pht0991- Posts : 222
Thanked : 3
24/02/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
thằng Thái spam vãi thật.
Thank bác Tâm!
Thank bác Tâm!
pklove1910- Posts : 207
Thanked : 3
11/09/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
pklove1910 đã viết:thằng Thái spam vãi thật.
Thank bác Tâm!
spam cha may
pht0991- Posts : 222
Thanked : 3
24/02/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
Thằng Thái spam quá có người bức xúc rồipht0991 đã viết:pklove1910 đã viết:thằng Thái spam vãi thật.
Thank bác Tâm!
spam cha may
shippou777- Posts : 460
Thanked : 8
11/10/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
thank bác Tâm nha..để vào lớp hôn cái,động viên
catretrang- Posts : 76
Thanked : 5
19/09/2011
Tài Sản
Thú nuôi:
Re: 7 bài tập về java Have Full
Bác Tâm có mấy bài giải thực hành socket share đi.
Môn này ngu quá, éo biết gì.
Môn này ngu quá, éo biết gì.
shippou777- Posts : 460
Thanked : 8
11/10/2011
Tài Sản
Thú nuôi:
Similar topics
» 653 Game Java Cho Nokia ne`!
» [Java]Chương trình Client-Server sử dụng Socket ở chế độ có nối kết TCP/IP Đề tài LIST Tenthumuc
» [Java] trao đổi giữa 2 chương trình bằng Socket. Đề tài đọc số từ Client gởi lên Server
» [Java]Bài tập về nhà từ điển Anh-Việt trao đổi thông tin giữa 2 luồng trong 1 chường trình bằng ống dẫn Pipe
» [Java] trao đổi giữa 2 chương trình bằng Socket. Đề tài thực hiện phép toàn Operant1 OP Operant2
» [Java]Chương trình Client-Server sử dụng Socket ở chế độ có nối kết TCP/IP Đề tài LIST Tenthumuc
» [Java] trao đổi giữa 2 chương trình bằng Socket. Đề tài đọc số từ Client gởi lên Server
» [Java]Bài tập về nhà từ điển Anh-Việt trao đổi thông tin giữa 2 luồng trong 1 chường trình bằng ống dẫn Pipe
» [Java] trao đổi giữa 2 chương trình bằng Socket. Đề tài thực hiện phép toàn Operant1 OP Operant2
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|