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("*");}
}