包含java3或9输出的词条
今天给各位分享java3或9输出的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、用JAVA因式分解 并以9=3×3格式输出
 - 2、java 写一程序在控制台输出,今年所有日期尾号是3,6,9的日期.如:3号,6号,9号
 - 3、Java编程,如何输出1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10
 - 4、Java编程,批量读取txt文件,并将所有文件的第一行数据中的第3位到第9位输出到控制台。
 
用JAVA因式分解 并以9=3×3格式输出
//输出表达式那一段改成这样就可以了。
System.out.print("该数字不是素数,因式分解为:"+number+"=");
for(int j=2;number!=1;)
{
if(number%j==0)
{
number/=j;
System.out.print(j);
j = 2;
if(number != 1) {
System.out.print("*");
}
continue;
}
j++;
}
java 写一程序在控制台输出,今年所有日期尾号是3,6,9的日期.如:3号,6号,9号
/**
* 输出
* @param year 年份
*/
private void output(int year){
boolean bo = false; //是否是闰年
if (year % 4 == 0 year % 400 == 0){
bo = true;
}
for (int i = 1; i = 12; i++){
for (int n = 0; n 3; n++){
System.out.println("2017年" + i + "月" + n + "3日");
System.out.println("2017年" + i + "月" + n + "6日");
if (bo i == 2){
System.out.println("2017年" + i + "月" + n + "9日");
}
}
}
}
Java编程,如何输出1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10
package zhidao;
public class Test6 implements Runnable
{
int start = 0;
int times = 0;
Thread thread;
public Test6 ()
{
if (null == thread)
{
start ();
}
else
{
stop ();
}
}
public static void main ( String[] args )
{
new Test6 ();
}
public void start ()
{
if (null == thread)
{
thread = new Thread (this);
thread.setPriority (Thread.MIN_PRIORITY);
thread.setName (this.getClass ().getName ());
thread.start ();
}
}
public synchronized void stop ()
{
if (null != thread)
{
thread.interrupt ();
}
thread = null;
notifyAll ();
}
@Override
public void run ()
{
try
{
while (true)
{
if (times == 9)
{
stop ();
break;
}
start++;
if (start == 11)
{
times++;
start = times + 1;
}
System.out.print (start);
Thread.sleep (500);
}
}
catch (InterruptedException e)
{}
}
}
Java编程,批量读取txt文件,并将所有文件的第一行数据中的第3位到第9位输出到控制台。
我马上写一个给你。
package com.zeal.card; // 这里是我自己临时用的包名,你自己改一下就好了
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Demo {
/**
* 主方法
* @param args
*/
public static void main(String[] args) {
printData();
}
/**
* 读取TXT文档第一行数据中的第3位到第9位,并输出到控制台
*/
public static void printData() {
// 定义文本文件数组,这里是临时演示用,请自己改写
String[] txtFiles = {
"c:/a.txt",
"c:/b.txt",
"c:/c.txt",
};
// 遍历文件
for (int i=0; itxtFiles.length; i++) {
try {
// 得到文件
File file = new File(txtFiles[i]);
// 如果文件存在
if (file.exists()) {
// 建立缓冲包装器
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
// 读出一行(因为只是读一行,没必要遍历全部文件内容)
String temp = in.readLine();
// 如果不为空,并且长度至少为9
if (temp != null) {
if (temp.length() =9) {
String txt = temp.substring(2, 9);
System.out.println("取出数据:" + txt);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
PS:代码是死的,人是活的,上面代码只是纯粹为了实现你说的功能做的一个演示,写的不好,应该将变量写在循环之外的,我没考虑那么多,反正只是读取一行。如果你需要多次用到这个功能,建议你将其封装为一个方法,给一个文件名或者File类型的文件作为参数,返回值就是你要读取的第3到9位,这样可以重复使用。
java3或9输出的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java3或9输出的信息别忘了在本站进行查找喔。