此問題可以通過FILTER來解決
成都創(chuàng)新互聯(lián)長(zhǎng)期為上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為湞江企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,湞江網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
public void init(FilterConfig config) throws ServletException
{
this.requestEncoding = config.getInitParameter("requestEncoding");
this.requestEncoding = ((this.requestEncoding == null) ? "utf-8" : this.requestEncoding);
this.responseEncoding = config.getInitParameter("responseEncoding");
}
頁(yè)面的編碼方式后臺(tái)需要處理,如果不想每一個(gè)頁(yè)面單獨(dú)處理可以配置一個(gè)filter將字符集更改下,中文問題就解決了
1.
public?class?Gun?{??????????//設(shè)置一個(gè)槍類
private?String?name;??????//槍名????
private?int?num;??????????//子彈的個(gè)數(shù)
private??int??Id;???//槍的Id
static?int?count;???????
public??Gun(){}
public?Gun(String?name,?int?num,?int?id)?{
this.name=name;
this.num=12;
}
public?Gun(String?name,int?num)?{
this.name=name;
this.num=num;
this.Id=count++;
}?
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getNum()?{
return?num;
}
public?void?setNum(int?num)?{
this.num?=?num;
}
public??int?getId(){
return?Id;
}
public??void?setId(int?id)?{
Id?=?id;
}
public?void?fire(){???????//槍的發(fā)射方法
??
}
@Override
public?String?toString()?{????//覆寫toString?
return?"Gun?[name="?+?name?+?",?num="?+?num?+?",?Id="?+?Id?+?"]";
}??
}
public?class?Ak_47?extends?Gun?{
//構(gòu)造器的重載
public?Ak_47(){}???????//構(gòu)造器
public?Ak_47(String?name,int?num){???
super(name,num);
}
public??void?fire(){?????//發(fā)射子彈?????,每次射出3發(fā)
???super.setNum(super.getNum()-3);??//得到子彈的數(shù)目???
}
public?void??clip(){????//裝彈夾???每個(gè)彈夾30發(fā)子彈
???super.setNum(super.getNum()+30);???
}
public?String?toString(){?????//toString的重寫
???return?"槍名:"+super.getName()+"\t"+"編號(hào):"+super.getId()+"\t"+"子彈數(shù):"+super.getNum();
}
}
public?class?Usp?extends?Gun?{
public?Usp(){}
public?Usp(String?name,int?num){???
super(name,num);
}
?public??void?fire(){?????//發(fā)射子彈?,每次發(fā)射一發(fā)
???super.setNum(super.getNum()-1);??//得到子彈的數(shù)目???
???}
???public?void??clip(){????//裝彈夾
???super.setNum(super.getNum()+12);???
???}
???public?String?toString(){
???return?"槍名:"+super.getName()+"\t"+"編號(hào):"+super.getId()+"\t"+"子彈數(shù):"+super.getNum();
???}
}
public?class?GunTest?{
public?static?void?main(String[]?args)?{
Ak_47?ak=new?Ak_47("ak",20);//Ak-47的彈夾可以裝30子彈
Ak_47?bk=new?Ak_47("us",12);
ak.fire();
bk.fire();
ak.clip();
bk.clip();
System.out.println(ak);
System.out.println(bk);
}
}
可以了
public class Test {
public static void main(String[] args) {
MyRectangle rec = new MyRectangle(3, 5);
MyRectangle square = new MySquare(4);
System.out.println(rec.toString());
System.out.println(square.toString());
}
}
class MyRectangle{
protected double width;
protected double length;
public MyRectangle(double length, double width){
this.width = width;
this.length = length;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getArea(){
return this.width * this.length;
}
public String toString(){
return "長(zhǎng)方形的長(zhǎng)為:" + length + ", 寬: " + width + ", 面積為:" + getArea();
}
}
class MySquare extends MyRectangle{
public MySquare(double length){
super(length, length);
}
public double getArea(){
return Math.pow(super.width, 2);
}
public String toString(){
return "正方形邊長(zhǎng)為: " + super.length + ", 面積為: " + getArea();
}
}
----------測(cè)試
長(zhǎng)方形的長(zhǎng)為:3.0, 寬: 5.0, 面積為:15.0
正方形邊長(zhǎng)為: 4.0, 面積為: 16.0
"13423"
foo(0) 時(shí) output 值為"134"
foo(1) 詩(shī) output 值為"13423"
因?yàn)閒inally無論出沒出現(xiàn)異常都會(huì)要執(zhí)行的,哪怕你寫了return。所以finally語(yǔ)句塊常用來“收尾”工作。
import?java.util.Scanner;
/*輸入一個(gè)成績(jī),將該成績(jī)轉(zhuǎn)換為A、B、C、D和E:成績(jī)?cè)?0分以上,結(jié)果為A,成績(jī)?cè)?0-90之間,結(jié)果為B,成績(jī)?cè)?0-80之間,結(jié)果為C,成績(jī)?cè)?0-70之間,結(jié)果為D,成績(jī)?cè)?0分以下,結(jié)果為E。*/
public?class?Chengfabiao
{
public?static?void?main?(String[]?args)
{
Scanner?scanner?=?new?Scanner(System.in);
int?score?=?scanner.nextInt();
if(score90)
{
System.out.println("A");
}
else?if(score=80)
{
System.out.println("B");
}
else?if(score=70)
{
System.out.println("C");
}
else?if(score=60)
{
System.out.println("D");
}
else
{
System.out.println("E");
}
}
}
答案放在下面地址:
順便給我踩下空間^-^
本小牛聽了那六級(jí)大牛的建議后做了如下修改
第1題:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class wangquanshu extends Applet implements ActionListener
{
int aa[]={6,28,496,8128,130816,2096128,33550336},bb[]={0,0,0,0,0,0,0};
//6=1+2+3
//28=1+2+4+7+14
//496=1+2+4+8+16+31+62+124+248
//8128=1+2+4+8+16+32+64+127+254+508+1016+2032+4064
//在1到40000000這么多數(shù)里,只有七個(gè)完全數(shù),它們是:6,28,496,8128,130816,2096128,33550336
//java里int 32位 -2^31~2^31-1(大概20億,應(yīng)夠了)
int j,q;
Label lab1;
TextField text1;
Label lab2;
TextField text2;
Button but;
public void init()
{ lab1=new Label("請(qǐng)輸入上下限:");
text1=new TextField(8);
lab2=new Label(" - ");
text2=new TextField(8);
but=new Button("確定");
add(lab1);
add(text1);
add(lab2);
add(text2);
add(but);
but.addActionListener(this);
}
public void paint(Graphics g)
{int m=1; //用于控制輸出自由數(shù)的位置
for(int n=0;n7;n++)
{g.drawString(" "+bb[n],10,50+m*20);
m++;
}
}
public void actionPerformed(ActionEvent e)
{int s=0;
int a=Integer.parseInt(text1.getText());
int b=Integer.parseInt(text2.getText());
for(j=0;j7;j++)
{if(aa[j]aaa[j]b)
bb[j]=aa[j];
}
repaint();
}
}
第2題:
import java.io.*;
import java.text.DecimalFormat;
public class e
{public static void main(String args[])
{double ee=0;
for(int i=0;i=11;i++)
{ee=ee+1/re(i);
}
DecimalFormat a=new DecimalFormat("0.00000000");
System.out.println(a.format(ee));
}
static double re(int n)
{if(n==0||n==1) return 1;
else return n*re(n-1);
}
}