1. 如何用java輸出小豬臉圖像
publicclassPig{
publicstaticvoidmain(Stringargs[]){
System.out.println("-------我是小豬-----------");
System.out.println("╭︿︿︿╮");
System.out.println("{/@@/}");
System.out.println("((oo))");
System.out.println("︶︶︶");
System.out.println("天哪,我竟然還做這種東西,真尷尬....");
}
}
下面是運行截圖:
2. 請問下java中導出圖片怎麼做
package com.xolt;
import java.io.FileOutputStream;
import java.io.File;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;;
public class TestPOI {
public static void main(String[] args) {
FileOutputStream fileOut = null;
BufferedImage bufferImg =null;
BufferedImage bufferImg1 = null;
try{
//先把讀進來的圖片放到一個ByteArrayOutputStream中,以便產生ByteArray
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
bufferImg = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
bufferImg1 = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
ImageIO.write(bufferImg,"jpg",byteArrayOut);
ImageIO.write(bufferImg1,"jpg",byteArrayOut1);
//創建一個工作薄
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("poi picT");
//HSSFRow row = sheet1.createRow(2);
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,512,255,(short) 1,1,(short)10,20);
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0,0,512,255,(short) 2,30,(short)10,60);
anchor1.setAnchorType(2);
//插入圖片
patriarch.createPicture(anchor , wb.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
patriarch.createPicture(anchor1 , wb.addPicture(byteArrayOut1.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
fileOut = new FileOutputStream("c:/workbook.xls");
//寫入excel文件
wb.write(fileOut);
fileOut.close();
}catch(IOException io){
io.printStackTrace();
System.out.println("io erorr : "+ io.getMessage());
} finally
{
if (fileOut != null)
{
try {
fileOut.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
poi中圖片到到excel的方法 你需要准備poi包 試試看看
3. 用java輸出以下圖形,怎麼做 * ** *** ****
實現思路:就是通過內層循環得到」*「的個數,外層循環控制換行。
for(int i=0;i<4;i++){
for(int j=0;j<=i;j++){
System.out.print("*");
}
System.out.println("");
}
備註:如果不想回換行的話,直接去掉外答層循環即可。
4. java中輸出圖片的代碼
final ImageView iv=(ImageView)findViewById(R.id.iv);
屬 Button bt=(Button)findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1)
{
// TODO: Implement this method
if(iv.getDrawable()!=null)
iv.setImageResource(R.id.photo);
else iv.setImageResource(0);
}
});
5. 用java編寫程序輸出如下圖形:
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.next();
int num = Integer.valueOf(str);
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= num - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print(i + " ");
}
System.out.println("");
}
}
}
6. java輸出圖形
public static void main(String[] args) {
版int n=10; //可以通抄過調襲整n值,調整輸出菱形的大小。n=行數權+1
for(int i=1;i<n;i++){
for(int j=1;j<=(i<n/2?n/2-i:i-n/2);j++){
System.out.print(" ");
}
for(int j=1;j<(i<n/2?2*i:2*(n-i));j++){
System.out.print("*");
}
for(int j=1;j<=(i<n/2?n/2-i:i-n/2);j++){
System.out.print(" ");
}
System.out.println();
}
}
7. 編寫Java程序,在控制台輸出圖形
偽代碼,供參考:
int k = 6; //定義最大長度
for(int i=1; i<=k; i++) {
for(int j=0; j<i; j++) {System.out.println("*");}
}
for(int i=k-1; i>=1; i--) {
for(int j=0; j<i; j++) {System.out.println("*");}
}