John_165 44 Junior Poster
rproffitt commented: When I first read this, I didn't see that tag. Anyhow, will re-read. +15
What have you tried so far ?
When I leave a comment (vote with comment ) under someone post , it will increase 2 points for vote up and 0 point for vote down. After I leave the comment and click the vote up button, the user earn 2 points. But after I vote down again, the comment get removed but the user still earning 2 points. The two points should be deducted too, no ?
Thanks.
Please post the code you have tried
Link was broken
Perhaps it is ISO 8583 message?
It collapses now :)
No, it still there after user reply.
Hope the traffic will increase after this !
I thought it will automatic minimize once we posted a reply instead of manual to minimize it.
But it is covering up the post....
It suppose to go down after we post a reply, no ?
After I reply a topic, the Reply to this Topic not going down.
To clarify ... you click the thumbs up link in the bottom left corner of a post and a whole new page loads??
No. There are no problem in the thumbs up and down link. The error is the comment in the bottom right corner.
First of all, I would like to say that the interface is nice, amazing, and user friendly!!
Thanks Dani and those who work hard on this !!!
But one thing I would like to comment is about the vote and comment. It seems like only users with high reputation allow to use this feature because I get this message when I click the vote up button
Oops!
You do not have the permissions required to access this page.
Would you like to go back?
Since this feature is not available to all users, why not just make it visible for those users only ?
Oh, thanks @happygeek
In programming section, java can be found in Software Development, Mobile Development and Computer Science.
Why we need three java as they refer to same thing ?
This is java code.
New huh? Then how do you explain the numerous other postings by you, from the exact same IP address....
How to check OP's ip address ?
Thanks James
class Solution {
public int solution(int[] A) {
int n = 0;
while (contains(A, ++n)) ;
return n;
}
public static boolean contains(int[] arr, int item) {
for (int n : arr) {
if (item == n) {
return true;
}
}
return false;
}
public static void main(String[] args) {
Solution s = new Solution();
int[] intArray = new int[]{5, 3, 2, 10};
int ans = s.solution(intArray);
System.out.println(ans);
}
}
Did the above code will find minimum value in array A ?
Where should I put the do/while loop ?
Question from codility test
Write a function:
class Solution { public int solution(int[] A); }
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−1,000,000..1,000,000].
This is what I have tried
class Solution {
public int solution(int[] A) {
int minValue = A[0];
do {
for (int i = 0; i < A.length; i++) {
if (A[i] < minValue) {
minValue = A[i];
}
}
} while (contains(A, ++minValue) == true);
return minValue;
}
public static boolean contains(int[] arr, int item) {
for (int n : arr) {
if (item == n) {
return true;
}
}
return false;
}
public static void main(String[] args) {
Solution s = new Solution();
int[] intArray = new int[]{1, 3, 6, 4, 1, 2};
int ans = s.solution(intArray);
System.out.println(ans);
}
}
I get infinity loop, no result displayed.
Can someone please point me out what is wrong here ?
Welcome Rizwan, hope you enjoy here
Just want to say hi
Many forums like to use email to inform, example CodeRanch and DreamInCode. Don't know what's the reason behind..
Can't wait to see the new version of this site :)
I'm excited for the future. Working on the new design right now and it's making me hopeful.
Can't wait to see the new design. Between, I still waiting for you to reply my message
What is your forum about ?
Thanks @rproffitt, I have the solution.
I should use ==
operator to compare the equality of two strings instead of =
.
Hey guys, I have a little bit confused on below code and output
Main
public class Main {
public static void main(String[] args) {
ClassA classA = new ClassA();
System.out.println("====== Before =====");
classA.checking();
System.out.println("===== After =====");
classA.checking();
}
}
Class A
public class ClassA {
boolean b = true;
public String checking() {
System.out.println("B value is " + b);
if (b = true) {
System.out.println("B is true");
b = false;
} else {
System.out.println("B is false");
}
return null;
}
}
Output
====== Before =====
B value is true
B is true
===== After =====
B value is false
B is true
Why the last line of value B in After will change from false to true ?
What errors you get ? Have you defined MainView in mainfest.xml ?
other than this how we get a full sentence in one line as an input from user
if you have questions, please start a new thread
To solve this, I need to move the data that need to be inserted to Processor.
public class Processor implements ItemProcessor<A, A> {
@Override
public A process(A i) throws Exception {
System.out.println("Processing..." + i);
i.setId("123");
i.setStatus("Active");
return i;
}
}
I trying to write a spring batch
using SpringBoot
. At first the program will read data from database, then write it to .csv
file format.
This is the code I have tried
Reader
@Bean
public ItemReader<A> Reader() throws Exception {
List list = new ArrayList<>();
JdbcCursorItemReader<A> reader = new JdbcCursorItemReader<A>();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "SELECT ID AS id FROM TABLE_A ";
list = jdbcTemplate.query(sql, new Mapper()); // store all retrieved data to list
reader.setSql(sql);
reader.setDataSource(dataSource);
reader.setRowMapper(new Mapper());
if (list != null) {
for (A c : (List<A>) list) {
c.setId("123"); // overwrite the id
c.setState("Active");
}
}
return reader;
}
Mapper
public class Mapper implements RowMapper<A> {
@Override
public A mapRow(ResultSet rs, int rowNum) throws SQLException {
A c = new A();
c.setId(rs.getString("id"));
}
Writer
@Bean
public ItemWriter<A> Writer() {
FlatFileItemWriter<A> csvFileWriter = new FlatFileItemWriter<>();
String exportFileHeader = "ID" + delimiter + "State";
StringHeaderWriter headerWriter = new StringHeaderWriter(exportFileHeader);
csvFileWriter.setHeaderCallback(headerWriter);
headerWriter.checkRepository();
String exportFilePath = "/home/xxx/Desktop/outputs/" + fileName + time() + ".csv";
csvFileWriter.setResource(new FileSystemResource(exportFilePath));
LineAggregator<A> lineAggregator = createStudentLineAggregator();
csvFileWriter.setLineAggregator(lineAggregator);
return csvFileWriter;
}
When I check the generated file, I can see the value id from database, but not 123. Value for the State is also empty . How can I overwrite the mapping value ?
Set the container's layout manager to null by calling setLayout(null).
Hi @Lokesh_8, I thought setting layout manager consider as bad practice ?
What I want to do is is create a new activity that has a starting screen, and after two seconds, transitions to the app I have provided.
Sounds like you need something call "splash screen"
I feel hard to understand how the LayoutManager work even the GUI is quite simple.
I trying to make the button place below the Tel No JTextField, but it placed beside Address JTextField , not below TelNo JTextField.
package gui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
public class OrderPage extends JPanel {
public static void main(String[] args) {
OrderPage order = new OrderPage();
order.createAndShowGUI();
JFrame frame = new JFrame();
frame = new JFrame();
frame.setTitle("Details");
frame.getContentPane().add(order);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void createAndShowGUI() {
String[] labels = { "Name: ", "Address: ", "Tel No: " };
int numPairs = labels.length;
// Create and populate the panel.
JPanel p = new JPanel(new SpringLayout());
JPanel p1 = new JPanel(new BorderLayout());
JButton button = new JButton("Confirm");
p1.add(button, BorderLayout.SOUTH);
for (int i = 0; i < numPairs; i++) {
JLabel l = new JLabel(labels[i], JLabel.TRAILING);
p.add(l);
JTextField textField = new JTextField(25);
l.setLabelFor(textField);
p.add(textField);
}
add(p);
add(p1);
// Lay out the panel.
SpringUtilities.makeCompactGrid(p, numPairs, 2, // rows, cols
6, 6, // initX, initY
6, 6); // xPad, yPad
}
}
Hi guys , is me again !
I get stucked on this question
Write a program that read an integer and display its smallest prime factors in ascending order. For example, if the input is 60, the output should be 2,3,5...
I came out with below code, but I get 2 2 3 5.How to have only one 2 ?
package chapter4;
import java.util.Scanner;
public class Exercise4_16 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
Exercise4_16 exe = new Exercise4_16();
int value = input.nextInt();
exe.primeFactors(value);
}
public void primeFactors(int value) {
while (value % 2 == 0) {
System.out.print(2 + " ");
value = value / 2;
}
for (int i = 3; i <= Math.sqrt(value); i = i + 2) {
while (value % i == 0) {
System.out.print(i + " ");
value /= i;
}
}
if (value >= 2) {
System.out.print(value);
}
}
}
If you used 10000 instead of 1000 you would get 21.
Yes, you're right ! Just realize I wrote 10000 instead of 1000.
10 to the 3rd power EQUALS 1000. It is not GREATER THAN 1000.
I also removed the EQUALS sign so can get value GREATER THAN 1000.
Thanks guys!