我有一个字符串列表
0-30 31-60 61-90 91-120 365+
我想要一个可以放入java split方法的正则表达式来获得第一个no,即
0 31 61 91 365
目前我正在使用这个逻辑:
if(str.endsWith("+") ){
str= str.substring(0, str.length()-1);
}
String Num = str.split("-")[0];
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法?
谢谢
所以,我编写了一个程序来自己将一个用户输入插入到堆栈中.但是,尽管我进行了严格的尝试,但我无法正确插入数据.它显示已插入数据,但在显示时,显示垃圾值.这是我的主要功能:
//Stack
#include<stdio.h>
#include<stdlib.h>
#define MAXSTK 10
void push(int *, int, int *, int);
//void pop();
void show_stack();
int main()
{
int ch, ch1, stack[MAXSTK], top=-1;
do{
printf("\n <<Stack MENU>>");
printf("1. Add Element");
printf("2. Delete Element");
printf("3. Show Stack");
printf("4. Exit menu");
printf("\n Enter your choice->");
scanf("%d", &ch);
switch(ch)
{
case 1: printf("\n Enter element to add->");
scanf("%d",&ch1);
push(stack,ch1, &top, MAXSTK);
break;
/* case 2: pop();
break;*/
case 3: printf("\n The stack is->");
show_stack(stack, MAXSTK);
break;
default: printf("\n Invalid Choice!!!"); …Run Code Online (Sandbox Code Playgroud) 到目前为止,在链表中,我只使用了一个temp节点来遍历给定链表的不同操作,这非常容易。
Now an assignment of a book demands to write a C code where the user input would be a number in the list and we have to compare the number just before the given number and the number just after the given number and tell which one is greater or equal, in case. For that, according to me, we need two pointers viz. prev and next on both side of current node to point to the two …
这就是我遇到问题的方法.我举个例子:
package check;
public class Check {
int a,b;
Check (int i,int j) {
a = i;
b = j;
}
}
Run Code Online (Sandbox Code Playgroud)
这可以.现在我想通过扩展创建一个子类Check.所以我写道:
class V extends Check {
}
Run Code Online (Sandbox Code Playgroud)
我写完后,在Eclipse中出现了一个十字架,单击它我发现了一条消息:
implicit super constructor Check() is undefined for default constructor. Must define an explicit constructor.
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了问题并添加了
V (int i, int j) {
super(i, j);
}
Run Code Online (Sandbox Code Playgroud)
Eclipse也提出了这个建议.现在我有两个问题.
class V?AFAIK,创建构造函数不是必需的,因为JAVA编译器会自动创建默认构造函数以继续其操作.同样来自消息,它似乎也需要一个默认的构造函数,但不是我写的,但正如我所说,JAVA不是自动创建的吗?V(int i, int j){ super.a=i; super.b=j}.,但我仍然遇到错误.这是为什么?这段代码不super.a=i; super.b=j一样super(i,j)吗?另外,在V类中,我可能不需要使用b,那么为什么我需要通过构造函数对其进行初始化呢?我现在正在学习基本的unix shell脚本。我正在尝试从此处编写我的用户名的代码,但是它不起作用。
代码是:
#
# Script to print user information who is currently logged in , current date & time
#
clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0
Run Code Online (Sandbox Code Playgroud)
我尝试使用$whoami而不是$user,但仍然没有显示我的用户名。这可能是什么问题?我在Ubuntu中使用vim编辑器。
我想从系统中获取当前月份作为字符串,也可以使用该java.sql.Date对象.
我已经尝试了下面的代码,但EclipsegetMonth()是通过以下方式进行的:
java.util.Date date = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date( date.getMonth() );
Run Code Online (Sandbox Code Playgroud)
为什么要通过?
我写了一段代码,以catch具体exception与帮助这个链接.它像是:
catch (SQLException sqle) {
// TODO Auto-generated catch block
String sqlMessage = sqle.getMessage();
String sqlState = sqle.getSQLState();
int vendorCode = sqle.getErrorCode();
System.out.println("Exception occurred:");
System.out.println("Message: " + sqlMessage);
System.out.println("SQL state: " + sqlState);
System.out.println("Vendor code: " + vendorCode);
}
Run Code Online (Sandbox Code Playgroud)
但我得到输出为:
java.sql.SQLException: ORA-00001: unique constraint (SYSTEM.PK_USERID) violated
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:543)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1028)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2960)
at accessdb.Dao.insertnewuser(Dao.java:32)
at Registration.doGet(Registration.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) …Run Code Online (Sandbox Code Playgroud) 0如果它是单个数字,我想在日期前添加一个.所以我做了一个代码:
public class Zero {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String zero="0";
Calendar cal = new GregorianCalendar();
int day1 = cal.get(Calendar.DAY_OF_MONTH);
String seven1=Integer.toString(day1);
System.out.println(""+seven1);
System.out.println(""+day1);
String added=zero.concat(seven1);
System.out.println(""+added);
int change=Integer.parseInt(added);
System.out.println(""+change);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当我打印时,change它7不打印07.其实我想做int 07而不是7.那么打印应该做哪些修改07?
注意 - 我没有提到if-else有意识地检查一位数或多位数的日期,因为它没有问题!
这是pop()函数,我写的是弹出一个堆栈的元素.到目前为止,我已成功将元素推入堆栈并显示堆栈.所以,我想我的pop()功能在某处做错了.这是我的pop功能:
void pop(int newstack[], int *newtop, int bound )
{
int item;
if(*newtop<0)
printf("\n CAUTION!!! UNDERFLOW");
else
{
item=newstack[*newtop];
*newtop--;
printf("\n Element popped->%d",item);
}
}
Run Code Online (Sandbox Code Playgroud)
我没有机会,我也发布了这个show()功能:
void show_stack(int newstack[], int *top)
{
int i;
printf("\n");
for(i=0;i<=*top;i++)
printf("%d",newstack[i]);
}
Run Code Online (Sandbox Code Playgroud)
我猜show函数没有错误.
我有一个拦截器,负责验证请求标头中存在的安全令牌。但对于 Swagger,我不想验证那部分。所以我在拦截器的排除模式中添加了 URL,但它不起作用。以下是我的排除代码:
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AuthorizationInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/health*","/**/swagger-ui.html/**");
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为我从拦截器收到授权错误。这里出了什么问题?默认 Swagger URL 为:http://localhost:3000/swagger-ui.html
编辑:我看到 swagger-ui.html 页面存在于 springfox jar 的 META_INF/resources 文件夹中。所以我添加了以下内容,excludePathPatterns("/health*", "classpath:/META-INF/resources/**", "**/swagger-ui.html")但这也不起作用。
java ×5
c ×3
date ×2
stack ×2
bash ×1
catch-block ×1
exception ×1
integer ×1
interceptor ×1
linked-list ×1
nodes ×1
printing ×1
split ×1
spring ×1
spring-boot ×1
unix ×1