Hỏi & đáp lập trình

Big thanks to Funnnny , ngon rồi :* .
 
ai check hộ xem mình viết sai ở đoạn nào cái :( nhập được số rồi mà sao bấm chạy nó chả hiện ra cái bảng kết quả, chả báo lỗi gì :(

PHP:
import javax.swing.JOptionPane;
public class Approximation {
	public static void main(String[] args) {
	
	String X = JOptionPane.showInputDialog("Enter x:");
	String DELT = JOptionPane.showInputDialog("Enter delta:");
	
	double x = Double.parseDouble(X);
	double delta = Double.parseDouble(DELT);
	
	int n = 3;
	int fact = 1;
		
	double num = x;
	double S = x;

	while (Math.abs(num)>delta)
	{
		fact *= (n-1)*n;
		num = Math.pow(x,n)/fact;
		S -= num;
		if (Math.abs(num)<delta)
		{
			JOptionPane.showMessageDialog(null,"x="+x+"\n"+
		         "delta="+delta+"\n"+
		         "sin="+S+"\n"+
		         "Stop term="+num+"\n"+
		         "N="+n);
		}
		else
		{
			n += 2;
			fact *= (n-1)*n;
	    	num = Math.pow(x,n)/fact;
		    S += num;
		    if (Math.abs(num)<delta)
		    {
			JOptionPane.showMessageDialog(null,"x="+x+"\n"+
		         "delta="+delta+"\n"+
		         "sin="+S+"\n"+
		         "Stop term="+num+"\n"+
		         "N="+n);
		    }
		    else
		    {
		    	n += 2;
		    }
		
		}
	}
		
	}	
}

test trong trường hợp này thì x là 3.14 , delta là 0.00001

EDIT check lại thì nhận thấy có nó xáy ra như thế này
nếu chỉ nhập x là 3, còn delta thì đến 0.0001 thì vẫn tính được kết quả, nhưng mà thêm 1 số 0 là tịt ngòi
còn nếu nhập x là 3.14, delta chỉ được đến 0.01 thôi chứ còn lại cũng tịt hết 8-} chả hiểu luôn


EDIT 2 thôi tự sửa được rồi, hóa ra phải để double fact nữa, tính ra số to quá thì fact không nhận đc :d
 
Chỉnh sửa cuối:
Cho mình hỏi cách viết code để auto number trong linux , tức là cái dãy số thứ tự giống excel đó . Thanks .
 
cho mình danh sách các lệnh của lập trình hợp ngữ VXL 8086/88
tất cả các lệnh và công dụng
 
cho mình xin các soft cần thiết để làm các flash sinh động đẹp ( kèm tài liệu càng tốt) :D
 
hỏi trong java cái
ví dụ mình có main method thế này
PHP:
s = JOptionPane.showInputDialog
            ("123");
        s = (s.trim()).toLowerCase();

giờ mình muốn tạo thêm method nữa nhưng phải viết thế nào để nó sử dụng s ở main method?
ví dụ ở method mới thì mình muốn nó extract data đi :|
PHP:
int i = s.indexOf(":");
String op = s.substring(0,i);
 
hỏi trong java cái
ví dụ mình có main method thế này
PHP:
s = JOptionPane.showInputDialog
            ("123");
        s = (s.trim()).toLowerCase();

giờ mình muốn tạo thêm method nữa nhưng phải viết thế nào để nó sử dụng s ở main method?
ví dụ ở method mới thì mình muốn nó extract data đi :|
PHP:
int i = s.indexOf(":");
String op = s.substring(0,i);

có nhìu cách:
- Sử dụng biến toàn cục
- Khai báo s là 1 thuộc tính của đối tượng
- Dùng từ khóa static
- ...
 
mấy bạn ơi giúp mình cái này với , ko biết cái máy tính bị gì nữa :(
à , chỉ mình cách fix luôn nha :D
whatbug.png
 
@rongdoVN: Nếu là lập trình thì lỗi do sử dụng đối tượng chưa được khởi tạo. Còn nếu là sử dụng phần mềm thì do lỗi lập trình nên chẳng fix được...
 
có bạn nào biết về Python (3.1) có thể share cho mình ebook về nó đc ko? Cái nào mà cho beginner đó. Tiếng anh hay tiếng việt đều đc
Cám ơn nhiều
 
Tớ đang làm 1 trang asp (Javascript) về phần nhập tin tức của trang web. Dùng cái CKEditor để nhập nội dung vào. Cột Contents trong SQL Server 2005 thì tớ để là ntext. Nhập một đoạn ngắn thì không sao. Nhưng tớ lên trên mạng copy một đoạn dài ví dụ như:

[SPOIL]Hong Qigong makes his first appearance in the novel during Guo Jing and Huang Rong's first adventure. Huang Rong is preparing some fine cuisine for Guo Jing and the fragrant scent of the food titillates Hong Qigong's senses. Hong Qigong appears and asks to taste the food. Huang Rong examines his physical appearance closely and sees his Dog-Beating Staff, which leads her to conclude that he is the famous "Northern Beggar".

Huang Rong tricks Hong Qigong into teaching Guo Jing martial arts in return for preparing fine cuisine every day for him. Hong Qigong succumbs to the temptation of delicious food and stays for almost a month with them. During that period of time, Hong Qigong teaches Guo Jing his "Eighteen Dragon-Subduing Palms". Initially, he is suspicious of Huang Rong when he recognises her as the daughter of his arch-rival "Eastern Heretic" Huang Yaoshi. He is reluctant to teach Huang Rong any martial arts but eventually he imparts the "Carefree Fist" to her.

Hong Qigong leaves them afterwards and meets them again during their encounter with Ouyang Ke. The lecherous Ouyang Ke is attempting to kidnap Cheng Yaojia and rape her but Cheng is saved by Guo Jing, Huang Rong and some members of the Beggars' Sect. Hong Qigong helps them drive away Ouyang Ke. Hong formally accepts Guo Jing as a disciple and finishes imparting the full set of the "Eighteen Dragon-Subduing Palms" to Guo.

Hong Qigong sets foot on Peach Blossom Island later and intervenes in the contest between Guo Jing and Ouyang Ke to win Huang Rong's hand-in-marriage. Huang Yaoshi allows Hong Qigong, Guo Jing and Zhou Botong to leave Peach Blossom Island later on a damaged ship. The ship sinks in the middle of the sea but the trio are rescued by Wanyan Honglie, whose ship coincidentally sails past the shipwreck. Onboard Wanyan Honglie's ship, "Western Venom" Ouyang Feng uses all sorts of means to force Hong Qigong and Guo Jing to hand over the highly-coveted Nine Yin Manual but fails.

Wanyan Honglie's ship sinks later while Hong Qigong and Ouyang Feng are engaged in a fierce battle. During the battle, Hong is poisoned after Ouyang uses his serpent venom on him. Guo Jing and Huang Rong manage to rescue Hong and they settle on a nearby island. Ouyang Feng and Ouyang Ke also set foot on the island and the five of them are stranded there. Hong uses all his inner energy to heal himself by purging out all the poison from his body, but loses his powers in the process.

Hong Qigong decides to pass the position of leader of the Beggars' Sect to Huang Rong and teaches her the "Dog-Beating Staff Skill". When Hong Qigong, Guo Jing and Huang Rong manage to leave the island, Hong follows them on their adventures together with Zhou Botong. They venture into the Imperial Palace where Hong says he wants to taste fine imperial cuisine again. He is briefly mentioned again in the scene on Mount Hua before the novel ends.[/SPOIL]

Thì bị báo lỗi:

The request filtering module is configured to deny a request where the query string is too long.

Có ai biết cách giải quyết thì chỉ hộ tớ với>.>
 
@Iroh
IIS Error code: 404.15 - The request filtering module is configured to deny a request where the query string is too long.
Lỗi do query string vượt quá giới hạn Request Limits của IIS.

Tìm đến folder %windir%\System32\inetsrv\config\.
Mở file ApplicationHost.config bằng notepad.
Tìm đến thẻ requestLimits.
Xóa bỏ maxQueryString. Hay thay đổi giá trị của nó lớn hơn giá trị hiện tại.
Giá trị mặc định của maxQueryString là 2048. Đoạn text trên kia gần 3KB rồi...

VD:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits
maxAllowedContentLength="30000000"
maxUrl="260"
maxQueryString="4096" />
</requestFiltering>
</security>
</system.webServer>
</configuration>

Lưu file ApplicationHost.config lại.

Hay
Dùng %windir%\system32\inetsrv\appcmd để thay đổi.
"appcmd list config /section:requestFiltering -text:requestLimits.maxQueryString" list các giá trị hiện thời của server.
"appcmd set config /section:requestFiltering /requestLimits.maxQueryString:4096" thay đổi giá trị thành 4096.

Source: iis.net
 
Chỉnh sửa cuối:
#include <iostream.h>
#include <stdio.h>

int bintodec(int n)
{
int s = 0;
int pow;
for (int i = 0;n > 0;++i)
{
pow = 1;
for (int j = 0;j < i;++j)
pow *= 2;
s += pow*(n%10);
n /= 10;
}
return s;
}
int main()
{
int n;
cout <<"Nhap n: ";
cin >>n;
cout <<"Chuyen co so: " <<bintodec(n) <<endl;
return 0;
}

Code trên mình viết để chuyển từ nhị phân sang thập phân, nhưng vẫn vướng nếu muốn chuyển từ dạng nhị phân biểu thị số âm sang thập phân. Nếu mình tạo một chuỗi kí tự rồi gán mã nhị phân vào, xét từ phần tử đầu tiên cho tới cuối thì có được không ?
 
Mấy bác có biết làm sao làm thư viện liên kết ngoài C, mấy cái include .h đó.
Nếu có cho mình biết ngôn ngữ luôn.
 
Câu hỏi hôm qua thì mình làm rồi, còn vướng lại mấy câu sau, trong đó khó nhằn nhất là câu c. Có ai biết thì gợi ý giùm mình chút, thanks nhiều :D
Viết đoạn chương trình C++ để thử nghiệm và trả lời các kết quả sau:
a. Khi gán x=a, với a là hằng số vượt ra ngoại phạm vi có thể chứ của biến nguyên x
thì kết quả nhận được sẽ như thế nào?
b. Khi gán x=y, với y là biến nguyên khác kiểu và có giá trị vượt ra ngoài phạm vi có
thế chứa của biến nguyên x thì kết quả nhận được sẽ như thế nào?
c. Khi gán x=p+q+r, với x kiểu long, p kiểu int, q kiểu unsigned int, r kiểu unsigned
char, thì giá trị lớn nhất / nhỏ nhất mà x nhận được là bao nhiêu? Giá trị đó có ảnh
hưởng nếu thay đổi thứ tự của p, q, r trong biểu thức tính tổng không?
 
Những cái này bạn cứ thử code 1 chương trình đơn giản là ok thôi mà
 
Back
Top