我正在开发一个带有10个元素(座位)的简单预订系统.我想检查是否已设置1到5的元素.如果是,则将元素从6设置为10(副Versa).
不应为元素分配多于一次的值.我的代码到目前为止.
boolean[] seats = new boolean[10];
Scanner input = new Scanner(System.in);
System.out.print("Choose FirstClass(1) / Economy(2): ");
int flightClass = input.nextInt();
for (int j = 0; j < seats.length; j++) {
System.out.println("\nEnter Seat Number: ");
int enterSeat = input.nextInt();
if (flightClass == 1) {
if (enterSeat >= 0 && enterSeat <= 5) {
System.out.println("You're in the First Class.");
seats[enterSeat] = true;
System.out.printf("You're Seat Number is %d\n", enterSeat);
}
} else if (flightClass == 2) {
if (enterSeat >= 6 && …Run Code Online (Sandbox Code Playgroud) 
我想在HTML文档中添加空格,就像橙色矩形内的空格一样.我不知道它的专业称谓的技术术语.道歉.
因为我正在探索ArrayLists,所以我这样做很有趣.我知道如何使用模数运算符来检查它是否可被3整除.但是,已经知道如何将它与arrayList一起使用.
public static void main(String[] args) {
//Print out only a set of numbers divisible by 3 from an array.
ArrayList<Integer> division = new ArrayList<Integer>();
//Add a set of numbers.
Division.add(10);
Division.add(3);
Division.add(34);
Division.add(36);
Division.add(435);
Division.add(457);
Division.add(223);
Division.add(45);
Division.add(4353);
Division.add(99);
//How can I fix the logic below?
if(Division.get() % 3 == 0)
}
Run Code Online (Sandbox Code Playgroud)
}
我的逻辑搞砸了.我只是试图找到一种方法来删除ArrayList中的重复项而不使用HashSet.
public static void main(String[] args) {
ArrayList<String> wordDulicate = new ArrayList<String>();
wordDulicate.add("Tom");
wordDulicate.add("Jones");
wordDulicate.add("Sam");
wordDulicate.add("Jamie");
wordDulicate.add("Robie");
wordDulicate.add("Helen");
wordDulicate.add("Tom");
wordDulicate.add("Troy");
wordDulicate.add("Mika");
wordDulicate.add("Tom");
for (String dupWord : wordDulicate) {
if (wordDulicate.equals(dupWord))
System.out.println(wordDulicate.get(dupWord));
}
}
Run Code Online (Sandbox Code Playgroud) 我以为我收到了这个错误,因为我没有ojdbc14.jar部署内部<jbossas.home>/common/lib.在我这样做之后,这个问题仍然存在.
堆栈跟踪
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76)
gov.medicaid.services.impl.RegistrationServiceBean.findByUsername(RegistrationServiceBean.java:156)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
root cause
org.hibernate.exception.GenericJDBCException: Cannot open connection
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
org.hibernate.loader.Loader.doQuery(Loader.java:696)
root cause
org.jboss.util.NestedSQLException: Unable to get managed connection for MitaDS; - nested throwable: (javax.resource.ResourceException: Unable to get managed connection for MitaDS)
org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:46)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) …Run Code Online (Sandbox Code Playgroud) 我了解Envers会生成一个表来存储审计跟踪.是否可以手动分配我希望存储数据的表.而不是让Envers自己生成一个表?
像这样......
[img here] [这里的段落]
而不是我现在拥有的.
[img here]
[这里的段落]
<p> <div class="polaroid">
<img src="Me1.jpeg" title="Me" alt="Me" align="left" />
<p class="polo">That's Me!!!</p>
</div></p>
</div>
<div class="blocker03">
<p class="description">
blah blah blah blahblah blahblah blahblah blahblah blahblah blahblah blahblah blah
blah blahblah blahblah blahblah blahblah blahblah blahblah blahblah blahblah blah
blah blahblah blahblah blahblah blahblah blah</p>
</div>
Run Code Online (Sandbox Code Playgroud)
.blocker03 {
width:470px;
padding-left:60px;
margin:0 0 10px 25px;
font-size:12px;
display:inline-block;
}
.polaroid {
postion: relative;
float: right;
border: 3px solid #C6930A;
border-style:dotted;
background: #66594C; …Run Code Online (Sandbox Code Playgroud) 当我在Setters中只有if/else条件时,该程序无效.我得到了一个提示,我必须在构造函数中使用它们.有人可以向我解释..为什么?
另一个问题:您是否将if/else语句放在Constructor或Setters中?
//构造函数
public Invoice(String partNumber, String partDescription, int quantity,
double pricePerItem) {
super();
this.partNumber = partNumber;
this.partDescription = partDescription;
if (quantity <= 0)
quantity = 0;
else
this.quantity = quantity;
if (pricePerItem <= 0)
pricePerItem = 0.0;
else
this.pricePerItem = pricePerItem;
}
Run Code Online (Sandbox Code Playgroud)
//塞特斯
public void setQuantity(int quantity) {
if (quantity <= 0)
this.quantity = 0;
else
this.quantity = quantity;
}
public double getPricePerItem() {
return pricePerItem;
}
public void setPricePerItem(double pricePerItem) {
if (pricePerItem != 0.0)
this.pricePerItem = 0.0; …Run Code Online (Sandbox Code Playgroud) 我只是在练习麻省理工学院的一些Java作业.但是,我不确定如何找到第二大数字.http://ocw.csail.mit.edu/f/13
public class Marathon {
public static void main(String[] arguments) {
String[] names = { "Elena", "Thomas", "Hamilton", "Suzie", "Phil",
"Matt", "Alex", "Emma", "John", "James", "Jane", "Emily",
"Daniel", "Neda", "Aaron", "Kate" };
int[] times = { 341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412,
393, 299, 343, 317, 265 };
for (int i = 0; i < names.length; i++) {
System.out.println(names[i] + ": " + times[i]);
}
System.out.println();
System.out.println("Largest Timing " + Largest(times));
System.out.println();
}
public …Run Code Online (Sandbox Code Playgroud) 我不知道如何提出这个问题.但是,这两行代码之间有什么不同?
Set<Integer> a = new HashSet<Integer>();
for (int i = 0; i < 100; i++) {
a.add(i);
a.remove(i - 1);
}
System.out.println(a.size());
Run Code Online (Sandbox Code Playgroud)
我预计99将成为输出
输出为1
Set<Short> a = new HashSet<Short>();
for (Short i = 0; i < 100; i++) {
a.add(i);
a.remove(i - 1);
}
System.out.println(a.size());
Run Code Online (Sandbox Code Playgroud)
我预计99将成为输出
输出为100