「java实现读数」java怎么读取输入的数字

博主:adminadmin 2023-01-19 08:45:09 233

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

本文目录一览:

怎么用java编写下面这个程序

import java.util.Scanner;

public class TestAA {

private static final float ELEC_PRICE = 0.7f; //单价

private float lastMonth; //上个月的电表读数

private float currentMonth; //当前月的电表读数

private Scanner scan = null;

private float getLastMonth() {

return lastMonth;

}

private void setLastMonth() {

System.out.println("请输入上个月的电表读数:");

scan = new Scanner(System.in);

lastMonth = scan.nextFloat();

}

private float getCurrentMonth() {

return currentMonth;

}

private void setCurrentMonth() {

System.out.println("请输入这个月的电表读数:");

scan = new Scanner(System.in);

currentMonth = scan.nextFloat();

}

public static void main(String[] args) {

TestAA aa = new TestAA();

aa.setRecord();

aa.showRecord();

aa.calcUsedFee();

}

public void setRecord() {

setLastMonth();

setCurrentMonth();

}

public void showRecord() {

System.out.println("上个月的电表读数为:" + getLastMonth());

System.out.println("本月的电表读数为:" + getCurrentMonth());

}

public void calcUsedFee() {

float totalMeasure = getCurrentMonth() - getLastMonth();

System.out.println("电费合计:" + totalMeasure * ELEC_PRICE);

}

}

这个就当做参考吧。。。你说的无非就是“低耦合”的问题。。。还有像这种还是用接口实现吧。。。太懒不写了。。。方法实现如上。。。。

JAVA读数

但是第一个数取么 呵呵 自己把握吧

int a[] = { 0, 1, 8, 1, 9, 5, 1, 3, 9, 8, 2, 9, 5, 3, 1, 3, 6, 5, 4, 3, 8, 9, 6, 5, 9, 4, 0, 6, 7, 1, 4, 0, 2, 5, 3, 9, 6, 9, 9, 2, 5, 6, 0, 6, 7, 4, 5, 1, 5, 8, 9, 4, 3, 2, 0, 8, 2, 4, 4, 1, 5, 9, 3, 6, 5, 1, 2, 2, 7, 9, 6, 4, 0, 2, 2, 1, 9, 6, 8, 0, 1, 8, 4, 5, 2, 3, 5, 9, 2, 8, 7, 1, 3, 1, 5, 1, 8, 1, 3, 0 };

for(int i=0;ia.length;i+=9)

{

if(a[i]5000000)

System.out.print(a[i]+" ");

else

continue;

}

呵呵 看得懂吧 只是 这种程序 还是自己多动手的好 刚开始就是要做这种东西 并不是做出来就好 而是要看怎样更加简单 更快 呵呵 加油!!!

哪里的问题啊 我试过了啊 靠

如何用java设置上月,这月电表读数,并输出

//载入系统输入扫描仪

import java.util.Scanner;

public class Number{

    public static void main(String[] args){

        //载入Scanner工具

        Scanner input = new Scanner(System.in);

        System.out.print ("输入上月电表读数:");

        //获取上月读数

        Double a = input.nextDouble();

        System.out.print ("输入本月电表读数:");

        //获取本月读数

        Double b = input.nextDouble();

       //输出上月,本月读数(分两行输出)

        System.out.println("上月电表读数为:"+a);

        System.out.println("本月电表读数为: "+b);

        }

}

用java语言怎么实现内存的读写

java都是在内存中操作的。

所有变量、所有数据都会在内存中

只是有个区别是:有些内存会被回收。即,一段时间后你就再也拿不到。

有些是永远不回收。直到服务器关闭。这就是你所想要的。

其实现方式有多种。

常用的是application.

用java从串口读取数据然后显示在网页上,能实现吗

用java从串口读取数据然后显示在网页上,能实现。

以下是对串口读写代码,来自网友百度知道网友。其它如何传递到网页自己搜索吧。

public static void process() {

try {

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements())

{

CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)//如果端口类型是串口则判断名称

{

if(portId.getName().equals("COM1")){//如果是COM1端口则退出循环

break;

}else{

portId=null;

}

}

}

SerialPort serialPort = (SerialPort)portId.open("Serial_Communication", 1000);//打开串口的超时时间为1000ms

serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);//设置串口速率为9600,数据位8位,停止位1们,奇偶校验无

InputStream in = serialPort.getInputStream();//得到输入流

OutputStream out = serialPort.getOutputStream();//得到输出流

//进行输入输出操作

//操作结束后

in.close();

out.close();

serialPort.close();//关闭串口

} catch (PortInUseException e) {

e.printStackTrace();

} catch (UnsupportedCommOperationException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

java怎么实现读取一个文件,拿到二进制流

Java读取二进制文件,以字节为单位进行读取,还可读取图片、音乐文件、视频文件等,

在Java中,提供了四种类来对文件进行操作,分别是InputStream OutputStream Reader Writer ,前两种是对字节流的操作,后两种则是对字符流的操作。

示例代码如下:

public static void readFileByBytes(String fileName){

File file = new File(fileName);

InputStream in = null;

try {

System.out.println("一次读一个");

// 一次读一个字节

in = new FileInputStream(file);

int tempbyte;

while ((tempbyte = in.read()) != -1) {

System.out.write(tempbyte);

}

in.close();

} catch (IOException e) {

e.printStackTrace();

return;

}

关于java实现读数和java怎么读取输入的数字的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。