導航:首頁 > 編程語言 > java的hello代碼

java的hello代碼

發布時間:2022-05-12 03:17:08

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");
}
}
閱讀全文

與java的hello代碼相關的資料

熱點內容
手機號碼如何加密 瀏覽:424
沈陽程序員培訓學校 瀏覽:538
一般伺服器如何配置 瀏覽:895
圖片怎樣加密發郵件 瀏覽:619
萬虹電腦文件夾密碼忘記了怎麼辦 瀏覽:631
rc108單片機 瀏覽:867
戰雷如何改變伺服器 瀏覽:674
mactelnet命令 瀏覽:51
壓縮袋壓縮了拿出來 瀏覽:401
安卓手機相機怎麼設置許可權 瀏覽:121
美女程序員轉行做主播 瀏覽:671
辦理解壓房產 瀏覽:575
道路工程概論pdf 瀏覽:388
超棒數學速演算法大全 瀏覽:937
小米易語言登錄源碼 瀏覽:31
磚牆內加密鋼筋 瀏覽:992
鄉關何處pdf 瀏覽:84
小豬領贊小程序源碼 瀏覽:336
python曲線如何原路返回 瀏覽:431
pdf快速看圖破解版 瀏覽:295