当前位置:首页 > 代码 > 正文

java输出源代码(输入输出java代码)

admin 发布:2022-12-19 22:33 143


本篇文章给大家谈谈java输出源代码,以及输入输出java代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求Java源代码:用Java实现输出:输入一个整数,输出此数为几位数。

import javax.swing.JOptionPane;

public class Test {

public static void main(String[] args)

{

String str=JOptionPane.showInputDialog("请输入一个整数:");

JOptionPane.showMessageDialog(null, "这个整数是"+str.length()+"位数");

}

}

求Java源代码:用Java实现输出:输入一个正整数,将该数的各位左右反转输出

不知道这样写是不是符合你的要求?

public class Temp {

public static void main(String[] args) {

String str = String.valueOf(12345);

StringBuffer buff = new StringBuffer();

System.out.println(str);

for(int i=str.length()-1;i=0;i--){

buff.append(str.charAt(i));

}

String retStr = buff.toString();

Integer retInt = Integer.valueOf(retStr);

System.out.println(retInt);

}

}

用java编写的有输入输出流源代码

/**

* 读写指定文件或者读写指定某一个文件夹下的全部文件(不包括文件夹)

* @throws Exception

*/

public static void moveFile() throws Exception {

Scanner scan = new Scanner(System.in);

System.out.println("请输入源路径:");//输入源文件地址,可以是文件夹,可以是具体某个文件

String uDisk = scan.nextLine();

File file = new File(uDisk);//获得读取文件

if ((file.exists())) {//当文件存在

System.out.println("请输入目标路径:");//文件复制目标路径

String targetFolder = scan.nextLine();

File target = new File(targetFolder);//获得写入文件

if (!target.exists()) {

if (!target.mkdir()) {

throw new Exception("创建目标目录失败");

}

} else if (!target.isDirectory()) {

throw new Exception("与目标目录同名的文件已经存在");

}

File[] temp = null;

if(file.listFiles()==null || file.listFiles().length=0){

temp=new File[]{file};//输入的源路径指定文件,将文件添加到文件数组中

}else{

temp = file.listFiles();//如果输入的源路径是文件夹,则获取文件夹下文件的个数

}

if ((temp != null) (temp.length 0)) {//文件数组temp有值

int i = 0;

for (int length = temp.length; i length; i++) {//循环文件数组

if (!temp[i].isDirectory()) {

String fileName = temp[i].getName();

File t = new File(targetFolder + File.separator

+ fileName);//创建输出文件

if (!t.createNewFile()) {

throw new Exception("创建输出文件失败");

}

FileOutputStream out = new FileOutputStream(t);//创建文件输出流

FileInputStream in = new FileInputStream(temp[i]);//创建文件输入流

byte[] buffer = new byte[256];

while (in.read(buffer) 0) {//循环输入流,直到输入流无数据

out.write(buffer);//写入文件

}

}

}

}

}

}

调用例子:

public static void main(String[] args) throws Exception {

moveFile();

}

关于java内部类的源代码,输出结果是多少

输出是:

5

5

请问有什么问题吗?

在主类Test里面的构造方法 Test() 里面输出的是 s3.a, 程序里面没有一处是改变s3.a的值得地方, 所以是5

r为Test.new Inner(), 所以r.a 还是 Inner里面给a的初始值 5

求java源程序代码:输入两个数,输出最大值

一下代码仅供参考

package com.kidd.test.zhidao;

import java.util.NoSuchElementException;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = 0;

int b = 0;

boolean next = false;

while (!next) {

System.out.print("请输入两个整数(用空格分隔):");

try {

a = sc.nextInt();

b = sc.nextInt();

next = true;

} catch (NoSuchElementException e) {

System.out.println("输入有误,请重新输入.");

sc.nextLine();

continue;

}

}

System.out.printf("最大值为:%d\n", a  b ? a : b);

}

}

关于java输出源代码和输入输出java代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/27885.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载