我有一个计算机程序,可以读取以后缀表示法编写的操作数和运算符的字符数组。然后,程序扫描数组,使用堆栈计算出结果,如下所示:
get next char in array until there are no more
if char is operand
push operand into stack
if char is operator
a = pop from stack
b = pop from stack
perform operation using a and b as arguments
push result
result = pop
import java.io.*;
import java.util.*;
public class Solution
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int k=s.nextInt();
long value=0L;
value=(k-(k/2)) * (k/2);
System.out.println(value);
我遇到的任务是查找一个子字符串在另一个字符串中的所有匹配项,我想知道解决这个问题的最佳算法是什么。
出于演示目的,我使用了字符串"The cat sat on the mat“,并搜索子字符串"at”的所有匹配项。这最终应该导致出现次数为3。因为我现在正在用java编程,所以我想到的第一件事就是:
public static void main(String[] args) {
int count=0;
String s = "The cat sat on the mat";
Pattern pattern = P
我有一个包含多行条件字符串的文件,我需要读取该文件并将逻辑条件字符串转换为实际代码。有几个参数,条件的每一行都检查一个或多个参数是否满足指定值或包含指定值。例如:
$parameterA = "value_1" AND ($parameterB CONTAIN "%value_2%" OR $parameterC = "value_3")
"=“、" and”和"OR“具有"==”、"&&“和"||”的含义。"%“是通配符。
在我将其转换为代码后,它应该如下所示:
if (o
我正试图使用堆栈来解决一个infix表达式,我的程序似乎抛出了一个ArrayIndexOutOfBoundsException。
你能指导我如何解决代码中的错误吗?
程序类
public class CS6084BTolani {
public static String evaluateInfix(String exps)
{
exps = exps.replaceAll(" ", "");//removing white spaces
System.out.println(exps);
St
我正在尝试创建一个正则表达式来识别 ,例如one、19、20、122<code>E 210</code>等等。我希望重用正则表达式的某些部分,因此正则表达式是由部分构建的,如下所示:
// replace <TAG> with the content of the variable
ONE_DIGIT = (?:one|two|three|four|five|six|seven|eight|nine)
TEEN = (?:ten|eleven|twelve|(?:thir|for|fif|six|seven|eigh|nine)teen)
TWO_DIGIT
如何将此代码中的字符转换为字符串?InfixToPostfix必须能够接受字符串而不是字符,这样它才能接受两位数字和空格。有什么建议吗?提前谢谢。
import java.util.Stack;
public class InfixToPostfix
{
private Stack operators = new Stack();
public InfixToPostfix()
{
}
public String toPostfix(String infix)
{
char[] characters = new char[100];
int i;
int len
以下是我需要组合在一起的样本数据集,如果仔细观察,它们大多是相似的文本行,但具有person id或ID的细微差别。
Unexpected error:java.lang.RuntimeException:Data not found for person 1X99999123 . Clear set not defined . Dump
Unexpected error:java.lang.RuntimeException:Data not found for person 2X99999123 . Clear set not defined . Dump
Unexpected error:
我有一个公司的数据库。我的应用程序接收按名称引用公司的数据,但名称可能与数据库中的值不完全匹配。我需要将传入的数据与它所引用的公司进行匹配。
例如,我的数据库可能包含一个名称为“A.B.widgets& Co Ltd”的公司。而我的输入数据可能会引用"AB Widgets Limited“、"A.B. Widgets and Co”或"A B Widgets“。
公司名称中的一些单词(A、B小部件)比其他单词(Co,Ltd,Inc等)更重要。避免错误匹配是很重要的。
公司的数量足够少,我可以在内存中维护他们的名称的地图,即。我可以选择使用Java而不是SQL来查
代码非常简单。它只检查一次所有字符,并替换它们的第一次出现。但是,对于输入= "aab“,它失败了。我也不知道原因。编程语言是java。
public class Solution {
/**
* @param str: a string
* @return: a boolean
*/
public boolean isUnique(String str) {
// write your code here
for(int i = 0; i <= 127; i++) {
s = Character.toString((char) i);