java中怎样从一系列字符串中读取小数_利用java设计在一串字符串中提取几个double类型有小数点的数字?...

这段Java代码展示了如何从一串字符串中提取并转换成double类型的小数值。通过遍历字符串,判断字符是否为数字或小数点,然后进行相应的计算和存储,最后将提取的小数打印出来。
摘要由CSDN通过智能技术生成

展开全部

07415f4a6608f74def577798afdb31a8.png

package sv;

import java.util.Scanner;

public class SadasTest {

public static Double gss(int n){

double a = 1;

for(int i = 1;i <=n;++i )

a = a*0.1;

return a;

}

public static void f(String s){

String str = "a" +s + "b";

int j = 0;

int x = 0;

int flag = 0;

int flag1 = 1;

double y = 0;

int gs = 1;

double[] arry = new double[100];

for(int i = 0;i 

if(Character.isDigit(str.charAt(i))|| str.charAt(i) == '.'){

flag = i;

if(Character.isDigit(str.charAt(i))){

if(flag1 == 1)

x = x*10+Integer.parseInt(String.valueOf(str.charAt(i)));

else{

y = y +(Integer.parseInt(String.valueOf(str.charAt(i))))*gss(gs);

gs++;

}

}else

flag1 = 0;

}else if(flag == i-1&&i !e68a843231313335323631343130323136353331333363366132= 1/*&&(flag == 0&& i != 1)*/)

{

arry[j] = x+y;

j++;

x = 0;

y = 0;

gs = 1;

flag1 = 1;

}

}

for(int m = 0;m 

int a = (int )arry[m];

if(arry[m] != a)

System.out.print(arry[m] + "\t");

else

System.out.print((int)arry[m] + "\t");

}

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String str = sc.next();

f(str);

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值