Ⅰ 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;
}
}
Ⅱ java的hello world怎么写
新建一个文件,名字HelloWorld.java
以下代码
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Ⅲ JAVA编写代码Hello World.java问题
额。。你这个保存文件名错了。用了public,那这个public的类必须和文件名相同。你把Hello World.java改成HelloWorld.java就可以了。求采纳
Ⅳ 请用JAVA编写一个简单的Hello程序
Hello World
public class HelloWorld
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
Ⅳ 怎样用Java程序输出“Hello World,”
1234567import java.lang.*; public class HelloWorld{public static void main(String[] args){System.out.println("HelloWorld");}}
Ⅵ java编写hello
首先你要新建一个源程序,比如源程序名字为"hello"
在编辑框,会自动生成一些头
class hello{
public static void main(String arfs[]){
System.out.println("hello");/////这句是你要加的
}
}
Ⅶ java输入一个字符串类似于hello,然后输出别的字符串代码要怎么写
题目的意思
就是根据输入的不一样, 进行判断和输出
例一
importjava.util.Scanner;
publicclassTest{
publicstaticvoidmain(String[]args){
Scannerinput=newScanner(System.in);
System.out.println("请输入你的性别男/女");
Stringsex=input.nextLine();//读取输入的一行
if(sex.equals("男")){//分情况输出
System.out.println("帅哥你好");
}elseif(sex.equals("女")){
System.out.println("美女你好");
}else{
System.out.println("你好");
}
}
}
输出
请输入你的性别男/女
男
帅哥你好
例二:
importjava.util.Scanner;
publicclassPrintDemo{
publicstaticvoidmain(String[]args){
String[]enNum={"zero","one","two","three","four","five"};
System.out.println("请输入0~5的数字.系统转换成英文并输出");
Scannerinput=newScanner(System.in);//控制台输入
while(true){
Stringline=input.nextLine();
if(line.equals("exit")){
System.out.println("系统退出");
System.exit(0);
}else{
intx=Integer.parseInt(line);
System.out.println("数字"+x+"转成英语:"+enNum[x]);//控制台输出
}
}
}
}
运行测试
请输入0~5的数字.系统转换成英文并输出
2
数字2转成英语:two
3
数字3转成英语:three
exit
系统退出
Ⅷ java这段代码为什么输出结果是s=hello a=hello false false
s本身是"hello"
a是 "he" + "llo",所以也是hello
s==a是false,因为两个都是对象,虽然字符相同,但内存地址不同,所以输出false。字符串若比较字符的话要用equals
Ⅸ 如何用Java编写Hello World
public class Hello
{
public static void main(string []args)
{
system.out.println("hello world");
}
}
Ⅹ 如何用java语言编写HelloWorld程序
java hello world其实很简单,有一个main函数作为程序的入口,有一个输出语句就ok了。
但是要注意:文件名必须要与类名一致
例如如下代码:HelloWorld.java 文件
publicclassHelloWorld{
publicstaticvoidmain(Sring[]args){
System.out.println("HelloWorld");
}
}