「java打印代码怎么写」java 打印代码

博主:adminadmin 2023-03-19 23:28:09 312

今天给各位分享java打印代码怎么写的知识,其中也会对java 打印代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

怎么编写Java程序打印九九乘法表?

用两个for循环,一个参数递增,另一个参数递减,代码如下:

public static void main(String[] args){

for (int i = 1; i = 9; i++){

for(int n = 1; n = i; n++) {

System.out.print( i + " x " + n + " = " + i * n + "\t");

}

System.out.println();

}

运行结果如下:

扩展资料:

Java中有三种主要的循环结构:

1、while 循环

while是最基本的循环,它的结构为:

while( 布尔表达式 ) {

 //循环内容}

只要布尔表达式为 true,循环就会一直执行下去。

2、do…while 循环

对于 while 语句而言,如果不满足条件,则不能进入循环。但有时候我们需要即使不满足条件,也至少执行一次。

do…while 循环和 while 循环相似,不同的是,do…while 循环至少会执行一次。

do {

//代码语句}while(布尔表达式);

3、for 循环

for循环执行的次数是在执行前就确定的。语法格式如下:

for(初始化; 布尔表达式; 更新) {

   //代码语句}

参考资料:

Oracle官方API接口-Java™ Platform, Standard Edition 7API Specification

W3cSchool-Java 循环结构 - for, while 及 do…while

java怎么打印Hello Word!

public int print(Graphics gra, PageFormat pf, int pageIndex) throws PrinterException {

System.out.println("pageIndex=" + pageIndex);

Component c = null;

//print string

String str = "

Hello Word!

";

//转换成Graphics2D

Graphics2D g2 = (Graphics2D) gra;

//设置打印颜色为黑色

g2.setColor(Color.black);

//打印起点坐标

double x = pf.getImageableX();

double y = pf.getImageableY();

switch (pageIndex) {

case 0:

//设置打印字体(字体名称、样式和点大小)(字体名称可以是物理或者逻辑名称)

//Java平台所定义的五种字体系列:Serif、SansSerif、Monospaced、Dialog 和 DialogInput

Font font = new Font("新宋体", Font.PLAIN, 9);

g2.setFont(font);//设置字体

//BasicStroke bs_3=new BasicStroke(0.5f);

float[] dash1 = {2.0f};

//设置打印线的属性。

//1.线宽 2、3、不知道,4、空白的宽度,5、虚线的宽度,6、偏移量

g2.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f, dash1, 0.0f));

//g2.setStroke(bs_3);//设置线宽

float heigth = font.getSize2D();//字体高度

System.out.println("x=" + x);

// -1- 用Graphics2D直接输出

//首字符的基线(右下部)位于用户空间中的 (x, y) 位置处

//g2.drawLine(10,10,200,300);

Image src = Toolkit.getDefaultToolkit().getImage("F:\\workspace\\QQ.png");

g2.drawImage(src, (int) x, (int) y, c);

int img_Height = src.getHeight(c);

int img_width = src.getWidth(c);

//System.out.println("img_Height="+img_Height+"img_width="+img_width) ;

g2.drawString(str, (float) x, (float) y + 1 * heigth + img_Height);

g2.drawLine((int) x, (int) (y + 1 * heigth + img_Height + 10), (int) x + 200, (int) (y + 1 * heigth + img_Height + 10));

g2.drawImage(src, (int) x, (int) (y + 1 * heigth + img_Height + 11), c);

return PAGE_EXISTS;

default:

return NO_SUCH_PAGE;

}

}

jsp页面如何用代码(java语言)实现打印功能?

如一楼所说,你的jsp源文件的java代码是在服务器上执行的,客户端接收到的只有html

用JavaScript打印吧

input

id="btnPrint"

type="button"

value="打印"

onclick="javascript:window.print();"

/

可以用样式控制,你想让那块打印就打印啊,样式如下:

style

type="text/css"

media=print

.noprint{display

:

none

}

/style

然后使用样式就可以:

p

class="noprint"不需要打印的地方/p

如何写一个字符在长方形区域内打印出来的JAVA代码

额~ 用字符组成一个 长方形么?

i:宽

j:长

for(int i = 0; i 3; i++)

{

for(int j = 0; j 7; j++)

{

System.out.print("*");

}

System.out.println();

}

java怎么打印出JFrame界面?就是我写出一个界面,现在想把它打印出来怎么写代码?

1.

/**

    * 开始打印

    */

   public void startPrint() {

      Toolkit kit = Toolkit.getDefaultToolkit(); //获取工具箱

      Properties props = new Properties();

      props.put("awt.print.printer", "durango"); //设置打印属性

      props.put("awt.print.numCopies", "2");

      if (kit != null) {

         //获取工具箱自带的打印对象

         PrintJob printJob = kit.getPrintJob(owner, "Print View Frame", props);

         if (printJob != null) {

            Graphics pg = printJob.getGraphics(); //获取打印对象的图形环境

            if (pg != null) {

               try {

                  this.paintAll(pg); //打印该窗体及其所有的组件

               } finally {

                  pg.dispose(); //注销图形环境

               }

            }

            printJob.end(); //结束打印作业

         }

      }

   }

2.OpenSwing里面有一个Demo,你可以看看

JAVA中用replace函数替换字符串,打印输出的代码,怎么写呢??

public

String

getStr(String

aa,String

bb)

{

String

str="abcdefg"

String

str1=str1.replace(aa,bb);//aa是被替换的字符串,bb是要替换成的内容

return

str;

}

如果有什么疑问,继续追问

关于java打印代码怎么写和java 打印代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。