在java中如何用代码输出将横向的文字改成纵向的文字JSP页面古诗横纵java代码,str为古诗横纵java代码你传到页面古诗横纵java代码的字符串变量
table
trtd
%if(str.length1){
for(int 1=0;istr.length;i++){%
%=str.substring(i,i+1)%br/
%}}%
/td/tr
/table
思路是每输出一个字符换行(未测试)
下面用HTML展示类似效果(复制即可)
html
headtitle/title/head
body
input type="text" id="a"
input type="button" value="https://www.04ip.com/post/转向" onclick="shu()"
/body
script language="javascript"
function shu()
{
var str2="";
var str1 = document.getElementById("a").value;
if (str1.length1)
{
for (var i=0; istr1.length; i++)
{
str2=str2+str1.substring(i,i+1)+"\n";
}
}
alert(str2);
}
/script
/html
用java完成唐诗测试游戏:从每句随机去掉一个字_代替,然后将去掉的字组合为4种选项,让用户选择正确答案 。Java程序古诗横纵java代码:
import java.util.Random;
public class Test0201 {
public static void main(String[] args) {
String[] poem = new String[]{"赠孟浩然",
"吾爱孟夫子", "风流天下闻",
"红颜弃轩冕", "白首卧松云",
"醉月频中圣", "迷花不事君",
"高山安可仰", "徒此揖清芬"};
String[] keys = new String[poem.length-1]; //存储每句中抽出古诗横纵java代码的单字
String[] items = new String[4];//存储4种备选答案选项
String correctItem;
int i;
drawKey(poem, keys);
correctItem = generateItems(keys, items);
System.out.println("以下唐诗的每一句都少一个字古诗横纵java代码,请选择合适的选项 , 将各选项中的字接顺序填充后,形成完整的唐诗古诗横纵java代码:\n");
System.out.println(poem[0]);
for(i=1; ipoem.length; i++){
System.out.println(poem[i] + (i%2==1 ?"," : " 。"));
}
System.out.println();
for(i=0; iitems.length; i++){
System.out.println(items[i]);
}
System.out.print("\n正确答案古诗横纵java代码:" + correctItem);
}
//从各句唐诗中抽取一个字并存储,将该字用“_”代替
public static void drawKey(String[] poem, String[] keys){
int i, pos;
Random rand = new Random();
for(i=1; ipoem.length; i++){
pos=rand.nextInt(poem[i].length());
keys[i-1] = poem[i].substring(pos, pos+1);
poem[i] = poem[i].substring(0, pos) + "_" + poem[i].substring(pos+1);
}
}
//组成备选答案选项,返回正确答案
public static String generateItems(String[] keys, String[] items){
Random rand = new Random();
int[] arr;
int n = keys.length;
int pos = rand.nextInt(4);//正确答案的位置
int i, j;
StringBuffer buff = new StringBuffer();
for(i=0; in; i++){
buff.append(keys[i]);
}
items[pos] = (char)('A' + pos) + ". " + buff.toString();
buff.delete(0, n);
【古诗横纵java代码 古诗横着写】for(i=0; i4; i++){
if(i == pos){
continue;
}
arr = generateArray(n);
for(j=0; jn; j++){
buff.append(keys[arr[j]]);
}
items[i] =(char)('A' + i) + ". " +buff.toString();
buff.delete(0, n);
}
return items[pos];
}
//生成由n个数字[0, n-1]组成的随机数数组
private static int[] generateArray(int n){
int[] arr = new int[n];
Random rand = new Random();
int i;
for(i=0; in;){
arr[i] = rand.nextInt(n);
if(isExistFigure(arr, i, arr[i])){
continue;
}
i++;
}
return arr;
}
//判断某数字在数组中是否存在
private static boolean isExistFigure(int[] arr, int n, int key){
for(int i=0; in; i++){
if(arr[i] == key){
return true;
}
}
return false;
}
}
运行测试:
第一次测试:
以下唐诗的每一句都少一个字,请选择合适的选项,将各选项中的字接顺序填充后,形成完整的唐诗:
赠孟浩然
吾_孟夫子,
_流天下闻 。
红颜弃轩_,
白首卧松_ 。
醉月频中_,
迷花不事_ 。
高山安_仰,
_此揖清芬 。
A. 爱徒君风可云冕圣
B. 云徒君风冕圣爱可
C. 君冕圣可风云徒爱
D. 爱风冕云圣君可徒
正确答案:D. 爱风冕云圣君可徒
第二次测试:
以下唐诗的每一句都少一个字,请选择合适的选项 , 将各选项中的字接顺序填充后,形成完整的唐诗:
赠孟浩然
吾爱孟夫_,
风流天下_ 。
红颜弃_冕,
_首卧松云 。
醉月频_圣 ,
迷花_事君 。
高山_可仰,
徒此揖_芬 。
A. 不白闻子中轩清安
B. 子闻轩白中不安清
C. 白不闻轩清安子中
D. 清子不白中安轩闻
正确答案:B. 子闻轩白中不安清
写一个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;}
//创建图像,先将逆时针旋转古诗横纵java代码了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"+
"谁爱风流高格调古诗横纵java代码?\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"+
"五湖烟水独忘机古诗横纵java代码?\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怎么把一首诗从横的变竖的具体实现代码如下古诗横纵java代码:
package test;
public class Test
{
public static void main(String[] args)
{
String separator = System.getProperty("line.separator");
String str = "床前明月光" + separator + "疑是地上霜" + separator +"这是最长古诗横纵java代码的一行" + separator + "最短古诗横纵java代码的一行";
String[] strArray = str.split(separator);
int maxLine = 0;
String tmpStr = null;
for (int i = 0; istrArray.length; i++)
{
if (strArray[i].length()maxLine)
{
maxLine = strArray[i].length();
}
}
for (int j = 0; jmaxLine; j++)
{
for (int i = 0; istrArray.length; i++)
{
if (j = strArray[i].length())
{
tmpStr = "\t";
}
else
{
tmpStr = "\t" + strArray[i].charAt(j);
}
System.out.print(tmpStr);
}
System.out.println("");
}
}
}
关于古诗横纵java代码和古诗横着写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 音响u盘怎么播放音乐,音响u盘怎么播放音乐视频
- go语言内网dns服务器 golang服务器
- 电子商务的erp系统设计与实现,erp 电子商务
- 毕业设计新风量怎么计算,新风系统毕业论文
- 电脑屏幕怎么能自动熄屏幕,怎样设置电脑屏幕自动熄灭时间
- python输出列函数 python输出一列数据
- linux各种命令配置 linux中各种命令
- 蜜疯直播内容是什么,蜜疯直播挣钱吗
- vcpdf转word的简单介绍