「java输出数据」java输出数据怎么五个一行

博主:adminadmin 2023-03-17 19:28:09 287

今天给各位分享java输出数据的知识,其中也会对java输出数据怎么五个一行进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java中输入输出流如何把数据输出为Excel表格形式

实现代码如下:

import org.apache.poi.hssf.usermodel.*;

import java.io.FileOutputStream;

import java.io.IOException;

publicclass CreateCells

{

publicstaticvoid main(String[] args)

throws IOException

{

HSSFWorkbook wb = new HSSFWorkbook();//建立新HSSFWorkbook对象

HSSFSheet sheet = wb.createSheet("new sheet");//建立新的sheet对象

// Create a row and put some cells in it. Rows are 0 based.

HSSFRow row = sheet.createRow((short)0);//建立新行

// Create a cell and put a value in it.

HSSFCell cell = row.createCell((short)0);//建立新cell

cell.setCellValue(1);//设置cell的整数类型的值

// Or do it on one line.

row.createCell((short)1).setCellValue(1.2);//设置cell浮点类型的值

row.createCell((short)2).setCellValue("test");//设置cell字符类型的值

row.createCell((short)3).setCellValue(true);//设置cell布尔类型的值

HSSFCellStyle cellStyle = wb.createCellStyle();//建立新的cell样式

cellStyle.setDataFormat(HSSFDataFormat.getFormat("m/d/yy h:mm"));//设置cell样式为定制的日期格式

HSSFCell dCell =row.createCell((short)4);

dCell.setCellValue(new Date());//设置cell为日期类型的值

dCell.setCellStyle(cellStyle); //设置该cell日期的显示格式

HSSFCell csCell =row.createCell((short)5);

csCell.setEncoding(HSSFCell.ENCODING_UTF_16);//设置cell编码解决中文高位字节截断

csCell.setCellValue("中文测试_Chinese Words Test");//设置中西文结合字符串

row.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_ERROR);//建立错误cell

// Write the output to a file

FileOutputStream fileOut = new FileOutputStream("workbook.xls");

wb.write(fileOut);

fileOut.close();

}

}

Java是由Sun Microsystems公司推出的Java面向对象程序设计语言(以下简称Java语言)和Java平台的总称。由James Gosling和同事们共同研发,并在1995年正式推出。Java最初被称为Oak,是1991年为消费类电子产品的嵌入式芯片而设计的。1995年更名为Java,并重新设计用于开发Internet应用程序。

用Java实现的HotJava浏览器(支持Java applet)显示了Java的魅力:跨平台、动态Web、Internet计算。从此,Java被广泛接受并推动了Web的迅速发展,常用的浏览器均支持Javaapplet。另一方面,Java技术也不断更新。Java自面世后就非常流行,发展迅速,对C++语言形成有力冲击。在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。2010年Oracle公司收购Sun Microsystems。

在jsp中的java脚本中输出数据时可以使用什么对象的pri

在jsp中的java脚本中输出数据时可以使用out对象的print。根据相关信息查询显示,在jsp中的java脚本中输出数据时可以使用out对象的print,是用来输出的。

java怎么输出数值占两个字符空间

就是把大于 0xff 的字符都作为两个字符(当然是在 GBK 环境下)

Java code

public static int count(String str) {

if(str == null || str.length == 0) {

return 0;

}

int count = 0;

char[] chs = str.toCharArray();

for(int i = 0; i chs.length; i++) {

count += (chs[i] 0xff) ? 2 : 1;

}

return count;

}

或者你直接使用 int len = str.getBytes("gbk");

上面代码假设你的数据库编码格式是 GBK 的,而不是 UTF-8 的,如果是 UTF-8 的话,上面的代码无效!

1字节等于8比特,一个字母是1字节,而一个汉字要用2个字节。

一个汉字=2个字符

Java的常用输入输出语句?

常用的输入语句是:

输入字符串:new Scanner(System.in).next();

输入整数:new Scanner(System.in).nextInt();

输入小数:new Scanner(System.in).nextDouble();

常用的输出语句:

换行输出: System.out.println(变量或字符串);

非换行输出: System.out.print(变量或字符串);

换行输出错误提示(默认是红字):System.err.println(变量或字符串);

不换行输出错误提示(默认是红字): System.err.print(变量或字符串));

java怎么输出不是基础类型的数据

1.java的基本数据类型的声明与使用

java基本数据类型有四类,分别是:

整数型:byte(1字节) short(2字节) int(4字节) long(8字节)

浮点型:float(4字节) double(8字节)

字符型:char(2字节)

布尔型:boolean(1位)

一共8个。 其中整数型有四个,浮点型有两个,字符型一个,布尔型一个。

对于基本数据类型,我们可以不对其进行赋值操作,如果不对其进行赋值,java会自动帮其赋予初始值。

2.类型转换

一般来说,低精度可自动转换为高精度

当然我们也可以强制转换将高精度数值赋给低精度变量,不过强制转换可能出现精度损失的状况

虚线转换可能会有精度损失。

3.输入,输出数据开始只需知道两个语句即可

输入:

Scanner reader = new Scanner(System.in) ;

reader.nextDouble();

这里的nextDouble可以换成nextShort…等等根据数据类型定义。

这里声明java是个严格区分大小写的语言

输出:System.out.println();或System.out.print();

前者和后者的差别就是前者在输出后自动换行,后者不会。

还有 System.out.printf(); 用法和C语言的一样。

示例:

import java.util.Scanner;

/**

* 让程序获取控制台用户输入的数据

*/

public class ScannerStudy {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("请输入数据,回车结束:");

String firstIn = in.nextLine();

System.out.println("获取控制台用户输入的字符串: "+firstIn);

int firstInt = in.nextInt();

System.out.println("获取控制台用户输入的int类型的数据: "+firstInt);

int firstLong = in.nextInt();

System.out.println("获取控制台用户输入的Long类型的数据: "+firstLong);

double firstDouble = in.nextDouble();

System.out.println("获取控制台用户输入的double类型的数据:"+firstDouble);

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

4.数组

在这里数组的使用有几个步骤:

4.1.声明

数组的元素类型 数组名[];

数组的元素类型 [] 数组名;

例如:float boy[]; (注意java不允许在声明数组中的方括号内指定数组元素的个数)

4.2.为数组分配内存空间

数组名 = new 数组元素的类型[数组元素的个数];

例如:boy = new float[4];

3.数组的使用

public class ArrayStudy {

public static void main(String[] args) {

int[] nums;

nums = new int[5];

nums[0] = 1;

nums[1] = 2;

System.out.println("nums[0]: "+nums[0]);

System.out.println("nums[1]: "+nums[1]);

}

}

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

二,实践积累部分

1.数据的转换与赋值问题

只需弄懂下面程序的错误点即可:

public class E

{

  public static void main(String args[])

  {

  int x = 8; 【代码1】

  byte b =128; 【代码2】//超出范围

  x = 12L; 【代码3】//12L表示long型数,需要强制转换才可以赋给int型

  long y = 8;  【代码4】//虽然可以,但不规范

  float z = 6.89;【代码5】//float类型赋值应该在数的后面加f

  }

}

2.注意System.out.println()与System.out.print()的区别

虽然二者都是输出函数,但前者是输出自动换行,后者则不换行

3.要熟悉数组工作原理

下面的例子较好的说明了数组的基本工作原理:

public class E

{

 public static void main(String args[])

 {

 int [] a={10,20,30,40},b[] = {{1,2},{4,5,6,7}};

  b[0] = a;

  b[0][1] = b[1][3];

  System.out.println(b[0][3]);

  System.out.println(a[1]);

 }

}

1

2

3

4

5

6

7

8

9

10

11

1

2

3

4

5

6

7

8

9

10

11

如果你能正确推算出这个程序的输出结果,那么你对数组的内部工作原理了解不错了。

正确答案是:40 7

java输出数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java输出数据怎么五个一行、java输出数据的信息别忘了在本站进行查找喔。