assignment java_Java 关于我的Assignment

展开全部

import java.util.Scanner;

public class Demo {

/**

* @param args

*/

public static void main(String[] args) {

62616964757a686964616fe78988e69d8331333337613165String s = "";

Scanner scanner = new Scanner(System.in);

System.out.println("Enter sentence:");

s = scanner.nextLine();

int length = s.length();

int acLength = 0;

int wcLength = 0;

int ntLength = 0;

for(int i=0;i

if((s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') || (s.charAt(i) >= '0' && s.charAt(i) <= '9')){

acLength++;

}else if(s.charAt(i) == ' '){

wcLength++;

}

}

String ss = s.replaceAll(" +", " ");

ntLength = ss.split(" ").length;

System.out.println("sentence statistics:");

System.out.println("      -Length of sentence:        "+length);

System.out.println("      -Alphanumeric characters:   "+acLength);

System.out.println("      -Whitespace characters:     "+wcLength);

System.out.println("      -Number of tokens:          "+ntLength);

}

//The quick BROWN fox jumped over the 2 lazy dogs (or was it 3?).

}

The quick BROWN fox jumped over the 2 lazy dogs (or was it 3?).

sentence statistics:

-Length of sentence:        63

-Alphanumeric characters:   46

-Whitespace characters:     13

-Number of tokens:          14

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的Java程序,它可以将两种货币之间的汇率进行转换。在程序中,我们使用了一个HashMap来存储货币之间的汇率。您可以根据需要对其进行修改。 ```java import java.util.HashMap; import java.util.Scanner; public class CurrencyConverter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); HashMap<String, Double> exchangeRates = new HashMap<>(); exchangeRates.put("USD", 1.0); exchangeRates.put("EUR", 0.85); exchangeRates.put("GBP", 0.75); exchangeRates.put("JPY", 111.28); exchangeRates.put("CNY", 6.47); System.out.print("Enter the amount: "); double amount = scanner.nextDouble(); System.out.print("Enter the currency to convert from: "); String fromCurrency = scanner.next().toUpperCase(); System.out.print("Enter the currency to convert to: "); String toCurrency = scanner.next().toUpperCase(); double fromRate = exchangeRates.get(fromCurrency); double toRate = exchangeRates.get(toCurrency); double result = amount * (toRate / fromRate); System.out.println(amount + " " + fromCurrency + " is equivalent to " + result + " " + toCurrency + "."); } } ``` 运行程序后,您可以输入要转换的金额、要转换的货币和要转换成的货币,程序会计算并输出转换后的金额。例如,如果您要将100美元转换为欧元,您可以输入以下内容: ``` Enter the amount: 100 Enter the currency to convert from: USD Enter the currency to convert to: EUR ``` 程序将输出: ``` 100.0 USD is equivalent to 85.0 EUR. ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值