java代码诗词,Java的代码
java switch case语句的识别
你从控制台输入字符串,跟你程序里面写死的字符串比较是有差异的。原因是从控制台通过IO流来读取的字符串里面包含了其他附加信息(如,你按的回车键...),程序里面写死的字符串则只包含里那几个字而已。你可以直接把程序里的B换成"苦心人天不负",就OK了。
创新互联是一家专注于成都网站建设、网站设计与策划设计,西畴网站建设哪家好?创新互联做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:西畴等地区。西畴做网站价格咨询:18980820575
呵呵,希望对你有帮助。
用hbuilder写古诗的代码
可以。
HBuilder是DCloud(数字天堂)推出的一款支持HTML5的Web开发IDE。HBuilder的编写用到了Java、C、Web和Ruby。HBuilder本身主体是由Java编写,它基于Eclipse,所以顺其自然地兼容了Eclipse的插件。快,是HBuilder的最大优势,通过完整的语法提示和代码输入法、代码块等,大幅提升HTML、js、css的开发效率。
请问如何写一段java,实现输入文字的号码,就出对应的输出文字?
package test1;
import java.util.Scanner;
public class H{
String s[]= {"1","2","3","4","5"};
int i=0;
public H() {
while (is.length) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入序号");
try {
i=sc.nextInt();
System.out.println("\n"+s[i]);
} catch (Exception e) {
System.out.println("输入错误,请重新输入");
continue;
}
}
}
public static void main(String[] args) {
new H();
}
}
你只需要将数组内容换成你自己写的内容就行
求一个诗词默写的java代码(网页应用),要带校验答案的(答案在数据库中)
什么意思?就网页上面有一个文本框,让学生写诗歌(文字),然后系统进行验证对不对是吗?
写一个java程序 将一首古诗竖着排序从右往左读
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class PoetryTest {
public static void main(String[] args) throws Exception {
final JFrame f = new JFrame();
final ArrayListPoetry ps = PContents.load();
final PoetryLabel plabel = new PoetryLabel();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(plabel);
f.setSize(320,268);
f.setLocationRelativeTo(null);
f.setVisible(true);
plabel.setPoetry(ps.get(0));
f.setTitle(plabel.getTitle()+"-"+plabel.getAuthor());
plabel.addMouseListener(new MouseAdapter(){
int index;
public void mouseClicked(MouseEvent e){
++index;
index=index%ps.size();
Poetry p = ps.get(index);
plabel.setPoetry(p);
f.setTitle(plabel.getTitle()+"-"+plabel.getAuthor());
}
});
}
}
//呈现诗歌的标签类
class PoetryLabel extends JLabel{
private static final Color tColor = Color.white;//标题颜色
private static final Color aColor = Color.yellow;//作者颜色
private static final Color cColor = Color.LIGHT_GRAY;//内容颜色
private static final int fontSize=16;//字体大小
private static final int tType = Font.BOLD;//标题字体样式为粗体
private static final int aType = Font.ITALIC;//作者字体样式为斜体
private static final int cType = Font.PLAIN;//内容字体样式为普通样式
private static final float scaleFactor = 1.2f;//标题字体大小比其它字体大
private static final String fontName="SimSun";//字体名称
private static final int offset=5,space=5;
private Font font;
private AffineTransform at;
private Poetry poem;
public PoetryLabel(){
this.poem=new Poetry();
this.font=new Font(fontName,cType,fontSize);
this.setHorizontalAlignment(JLabel.CENTER);
this.setVerticalAlignment(JLabel.CENTER);
at = new AffineTransform();
at.setToRotation(Math.toRadians(-90));
font = font.deriveFont(at);//将字体逆时针旋转90°
}
public Poetry getPoetry() {
return poem;
}
//设置诗歌,来初始化标签内容
public void setPoetry(Poetry s){
this.poem=s;
this.repaint();
}
public String getTitle(){return poem.title;}
public String getAuthor(){return poem.author;}
//创建图像,先将逆时针旋转了90°的文件画上,然后将整幅图像顺时针旋转90°
private Image createImage(){
int x;
int y=offset;
int w = getTWidth(poem);
int h = getTHeight(poem);
BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = img.createGraphics();
//draw title
g.setColor(tColor);
Font tfont = font.deriveFont(font.getSize()*scaleFactor).deriveFont(tType);
g.setFont(tfont);
y+=tfont.getSize();
char[] cs = poem.title.toCharArray();
for(int i=0; ics.length; i++){
x=(i+1)*(tfont.getSize()+space)+offset;
g.drawChars(cs, i, 1, x, y);
}
//draw author
y+=space*2+tfont.getSize();
cs = poem.author.toCharArray();
tfont = font.deriveFont(aType);
g.setColor(aColor);
g.setFont(tfont);
for(int i=0; ics.length; i++){
x=(i+1)*(tfont.getSize()+space)+offset;
g.drawChars(cs, i, 1, x, y);
}
//draw contents
y+=space*3;
g.setColor(cColor);
g.setFont(font);
for(int i=0; ipoem.contents.size(); i++){
y+=fontSize+space;
cs = poem.contents.get(i).toCharArray();
for(int j=0; jcs.length; j++){
x=(j+1)*(tfont.getSize()+space)+offset;
g.drawChars(cs, j, 1, x, y);
}
}
g.dispose();
return this.getRotateImage(img);
}
//将图像顺时针旋转90°
private Image getRotateImage(final BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImg = new BufferedImage(h,w,2);
AffineTransformOp op = new AffineTransformOp(AffineTransform.
getRotateInstance(Math.toRadians(90),h/2,h/2),null);
return op.filter(img,newImg);
}
//绘图
public void paint(Graphics gg){
BufferedImage img = (BufferedImage)this.createImage();
int iw = img.getWidth();
int ih = img.getHeight();
Graphics2D g = (Graphics2D)gg;
int w = this.getWidth();
int h = this.getHeight();
g.setPaint(new GradientPaint(0,0,Color.DARK_GRAY,0,h,Color.black));
g.fillRect(0,0,w,h);
int x = (w-iw)/2;
int y = (h-ih)/2;
g.drawImage(img, x, y, this);
g.dispose();
}
//计算图片的高度
private int getTHeight(Poetry s) {
int h = offset*2+space*5;
h+=(int)(fontSize*(scaleFactor+1));
h+=(fontSize+space*2)*s.contents.size();
return h;
}
//计算图片的宽度
private int getTWidth(Poetry s) {
int tl = (int)(s.title.length()*(fontSize*scaleFactor+space)+offset*2);
int al = s.author.length()*(fontSize+space)+offset*2;
int t;
int max = tlal?tl:al;
for(int i=0; is.contents.size(); i++){
t = s.contents.get(i).length()*(fontSize+space)+offset*2;
max=maxt?max:t;
}
return max;
}
}
//诗歌类
class Poetry{
public String title;//标题
public String author;//作者
public ArrayListString contents=new ArrayListString();//内容
public void addLine(String s){this.contents.add(s);}//加入一行内容
}
//
class PContents{
public static String s=
"苏武庙\r\n"+
"温庭筠\r\n"+
"苏武魂销汉使前,\r\n"+
"古祠高树两茫然。\r\n"+
"云边雁断胡天月,\r\n"+
"陇上羊归塞草烟。\r\n"+
"回日楼台非甲帐,\r\n"+
"去时冠剑是丁年。\r\n"+
"茂陵不见封侯印,\r\n"+
"空向秋波哭逝川。\r\n"+
"\r\n"+
"贫女\r\n"+
"秦韬玉\r\n"+
"蓬门未识绮罗香,\r\n"+
"拟托良媒益自伤。\r\n"+
"谁爱风流高格调?\r\n"+
"共怜时世俭梳妆。\r\n"+
"敢将十指夸针巧,\r\n"+
"不把双眉斗画长。\r\n"+
"苦恨年年压金线,\r\n"+
"为他人作嫁衣裳。\r\n"+
"\r\n"+
"宫词\r\n"+
"薛逢\r\n"+
"十二楼中尽晓妆,\r\n"+
"望仙楼上望君王。\r\n"+
"锁衔金兽连环冷,\r\n"+
"水滴铜龙昼漏长。\r\n"+
"云髻罢梳还对镜,\r\n"+
"罗衣欲换更添香。\r\n"+
"遥窥正殿帘开处,\r\n"+
"袍裤宫人扫御床。\r\n"+
"\r\n"+
"利洲南渡\r\n"+
"温庭筠\r\n"+
"澹然空水对斜晖,\r\n"+
"曲岛苍茫接翠微。\r\n"+
"波上马嘶看棹去,\r\n"+
"柳边人歇待船归。\r\n"+
"数丛沙草群鸥散,\r\n"+
"万顷江田一鹭飞。\r\n"+
"谁解乘舟寻范蠡,\r\n"+
"五湖烟水独忘机?\r\n"+
"\r\n"+
"无题二首之一\r\n"+
"李商隐\r\n"+
"凤尾香罗薄几重,\r\n"+
"碧文圆顶夜深缝。\r\n"+
"扇裁月魄羞难掩,\r\n"+
"车走雷声语未通。\r\n"+
"曾是寂寥金烬暗,\r\n"+
"断无消息石榴红。\r\n"+
"斑骓只系垂杨岸,\r\n"+
"何处西南任好风?\r\n"+
"\r\n"+
"无题二首之二\r\n"+
"李商隐\r\n"+
"重帷深下莫愁堂,\r\n"+
"卧后清宵细细长。\r\n"+
"神女生涯原是梦,\r\n"+
"小姑居处本无郎。\r\n"+
"风波不信菱枝弱,\r\n"+
"月露谁教桂叶香?\r\n"+
"直道相思了无益,\r\n"+
"未妨惆怅是清狂。\r\n"+
"\r\n"+
"金陵图\r\n"+
"韦庄\r\n"+
"江雨霏霏江草齐,\r\n"+
"六朝如梦鸟空啼。\r\n"+
"无情最是台城柳,\r\n"+
"依旧烟笼十里堤。\r\n" +
"\r\n"
;
public static ArrayListPoetry load() throws Exception{
ArrayListPoetry list = new ArrayListPoetry();
BufferedReader br = new BufferedReader(new StringReader(s));
Poetry p = null;
String t = null;
while((t = br.readLine()) != null){
if(p==null)
p=new Poetry();
if(t.isEmpty()){
list.add(p);
p=null;
}
else if(p.title==null)
p.title=t;
else if(p.author==null)
p.author=t;
else
p.addLine(t);
}
return list;
}
}
网页标题:java代码诗词,Java的代码
本文链接:http://myzitong.com/article/dscjjgd.html