此问题可以通过FILTER来解决
成都创新互联长期为上千客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为浈江企业提供专业的成都网站建设、成都做网站,浈江网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
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");
}
页面的编码方式后台需要处理,如果不想每一个页面单独处理可以配置一个filter将字符集更改下,中文问题就解决了
1.
public class Gun { //设置一个枪类
private String name; //枪名
private int num; //子弹的个数
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(){ //枪的发射方法
}
@Override
public String toString() { //覆写toString
return "Gun [name=" + name + ", num=" + num + ", Id=" + Id + "]";
}
}
public class Ak_47 extends Gun {
//构造器的重载
public Ak_47(){} //构造器
public Ak_47(String name,int num){
super(name,num);
}
public void fire(){ //发射子弹 ,每次射出3发
super.setNum(super.getNum()-3); //得到子弹的数目
}
public void clip(){ //装弹夹 每个弹夹30发子弹
super.setNum(super.getNum()+30);
}
public String toString(){ //toString的重写
return "枪名:"+super.getName()+"\t"+"编号:"+super.getId()+"\t"+"子弹数:"+super.getNum();
}
}
public class Usp extends Gun {
public Usp(){}
public Usp(String name,int num){
super(name,num);
}
public void fire(){ //发射子弹 ,每次发射一发
super.setNum(super.getNum()-1); //得到子弹的数目
}
public void clip(){ //装弹夹
super.setNum(super.getNum()+12);
}
public String toString(){
return "枪名:"+super.getName()+"\t"+"编号:"+super.getId()+"\t"+"子弹数:"+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 "长方形的长为:" + 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 "正方形边长为: " + super.length + ", 面积为: " + getArea();
}
}
----------测试
长方形的长为:3.0, 宽: 5.0, 面积为:15.0
正方形边长为: 4.0, 面积为: 16.0
"13423"
foo(0) 时 output 值为"134"
foo(1) 诗 output 值为"13423"
因为finally无论出没出现异常都会要执行的,哪怕你写了return。所以finally语句块常用来“收尾”工作。
import java.util.Scanner;
/*输入一个成绩,将该成绩转换为A、B、C、D和E:成绩在90分以上,结果为A,成绩在80-90之间,结果为B,成绩在70-80之间,结果为C,成绩在60-70之间,结果为D,成绩在60分以下,结果为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");
}
}
}
答案放在下面地址:
顺便给我踩下空间^-^
本小牛听了那六级大牛的建议后做了如下修改
第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这么多数里,只有七个完全数,它们是:6,28,496,8128,130816,2096128,33550336
//java里int 32位 -2^31~2^31-1(大概20亿,应够了)
int j,q;
Label lab1;
TextField text1;
Label lab2;
TextField text2;
Button but;
public void init()
{ lab1=new Label("请输入上下限:");
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; //用于控制输出自由数的位置
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);
}
}