Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
This post was edited and submitted for review 4 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have an excel file from which I have to find the first few even numbers. I am facing trouble trying to print my list. Here is the snippet of my code :
List<String> contents = UtilFile.readFile(getServletContext(), filename);
List<Integer> copy = new ArrayList<Integer>();
List<Integer> store = new ArrayList<Integer>();
for (String s : contents) {
copy.add(Integer.parseInt(s));
}
Collections.sort(copy);
int i = 0;
for (i = 0; i < copy.size(); i++) {
if (copy.get(i) % 2 == 0) {
store.add(i);
}
}
response.getWriter().print("First 10 unique even numbers are: " + contents.toString());
When I run the code, all I see is an empty list. Here is the output :
First 10 unique even numbers are: []
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
when i add data to the table from textfield i get a replacement error, no new row.
enter image description here
enter image description here
i already tried deleting the table and re-creating it but still the error.How can I solve this?
My code
private void xuLyThemVaoGioHang() throws Exception {
DefaultTableModel dtmGioHang = (DefaultTableModel) tblGioHang.getModel();
dtmGioHang.setRowCount(0);
String ma = txtMaSPBanHang.getText();
String ten = txtTenSPBanHang.getText();
String donGia = txtDonGiaBanHang.getText();
int soLuong = Integer.parseInt(txtSoLuongBanHang.getText());
donGia = donGia.replace(",", "");
int donGiaSP = Integer.parseInt(donGia);
spBUS.docListSanPham();
loadDataTableSanPhamBan();
dtmGioHang.addRow(new Object[]{
ma,ten,soLuong,donGiaSP, dcf.format(soLuong * donGiaSP)
});
new MyDialog("Thêm thành công!!", MyDialog.SUCCESS_DIALOG);
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
public void getComputerPlayerTurn(String pid, ScopaCard card) {
//checkPlayerTurn(pid);
getPlayerHand(pid);
int tempInt = playerHand.size();
ArrayList<Rank> tempRanks = new ArrayList<Rank>
for (int i = 0; i < tempInt; i++) {
card = playerHand.get(i).get(i);
tempRanks.add(card.getRank());
}
}
That's my code for a method that I'm trying to create. The aim of this for loop is to get the cards in a players hand, and add their ranks to a different ArrayList. Everything is fine apart from the top line of the for loop (the one that has for (int i = 0; ...)). Here it is saying that a ( or [ is expected. I have no idea where though.
Cheers.
ArrayList<Rank> tempRanks = new ArrayList<Rank>
You forgot to put the constructor's brackets on the ArrayList. It should look like this:
List tempRanks = new ArrayList<>();
Your are missing the () at the end of array list declaration:
Syntax to declare array list ->
List<Rank> tempRanks = new ArrayList<Rank>();
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to print out values of an arrays in tabular format (in the pic) but it doesn't seem to be working. I know it has something to do with the for loop and but I'm not sure how to code it properly so it shows.
The array is user inputed so it could vary on how many "gifts" there are.
If I forgot to include anything, sorry this is my first post
public static void printGiftsReport(String[] giftArray, double[] priceArray,
String[] whomArray, double overUnderAverage)
{
//
{
System.out.printf("%-15s%10s%15s%15s%25s" ," #.", "For", "Gift",
"Price", "Over/ Under Average\n");
System.out.printf("%-15s%10s%15s%15s%25s", "---", "---", "----",
"-----", "-------------------\n");
for(int i = 0; i > whomArray.length ; i++)
{
if (priceArray[i] > overUnderAverage)
{
System.out.printf("%-10s%10s%25s%10.2f%25s", (i+1),
whomArray[i], giftArray[i], priceArray[i], "over\n");
}
else
{
System.out.printf("%-10s%10s%25s%10.2f%25s", (i+1),
whomArray[i], giftArray[i], priceArray[i], "under\n");
}
you're doing i>whomArray.Length which will never run since i is initialized to 0. what you want instead is i<whomArray.Length.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have tried to compare all elements in a list that have this locator :
70.000
I have tried this using AssertJ but it does not work:
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (int i = 0; i < listaPret.size(); i++){
assertThat(i).isBetween(50.000,80.000);
}
Adding the webpage where I try to check this
https://www.imobiliare.ro/vanzare-apartamente/timisoara?id=6923228
I am very new to selenium and automation testing including programing so please be pacient with me :D
Try this :
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
assertThat(listaPret.size()).isBetween(50.000,80.000);
if you're trying to get numbers from listaPret then use this:
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (int i = 0; i < listaPret.size(); i++){
double price = Double.parseDouble(listaPret.get(i).getText());
assertThat(price).isBetween(50.000,80.000);
}
As suggested by #mrfreester using for each loop to be safer (also better looking) :
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (WebElement item : listaPret) {
double price = Double.parseDouble(item.getText());
assertThat(price).isBetween(50.000,80.000);
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
https://projecteuler.net/problem=8 link to problem
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product.(number is in the code as String num)
The answer i am getting is "9205903071867879424" (wrong answer)
Please point out the mistakes in my code and also suggest your solution to solve the problem efficiently as possible.
I read the other threads about this problem but couldn't understand them and also there weren't enough efficient solutions.
public static void main(String[] args){
String num = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";
long product=1;
long greatestp=0;
long limit=13;
for (int i=0; i<num.length()-13; i++){
product = 1;
for (int j=0; j<limit; j++ ){
product = (long) (product * (int) (num.charAt(j+i)));
}
if (greatestp<product){
greatestp = product;
}
}
System.out.println(greatestp);
}
P.S. I'm a beginner at JAVA, I would appreciate if you explain your solution in detail.
charAt gives you the ascii charcode, not the actual digit. Therefore the fastest way is to subtract the value of '0' from it:
product = product * (num.charAt(i+j) - '0');