|
When posting your question please:- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-fou
|
|
|
|
|
Can anyone help me figure this out? I wrote the following code for my programming class.
package weekthreeassignments;
public class Odds {
public static void main(String[] args) {
int product = 1;
for (int i = 1; i <= 15; i++)
if (i % 2 == 1) {
product *= i;
}
System.out.println("Product of the odd integers from 1 to 15 is: " + product);
}
}
When I run the code I get the following error and how to fix it, but if you read the "Please define" part, I did define it that way. Why am I still erroring?
Error: Main method not found in class weekthreeassignments.Odds, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)
|
|
|
|
|
Seems like you created a JavaFX project, which by definitions puts application code in a JavaFX specific Application class. Thus, your main class has to extend it.
If you want to have the JavaFX GUI application, study a tutorial: JavaFX Tutorial - javatpoint
Otherwise create a normal java application project. Most IDEs call the normal java project type "Empty Project" or "Java Project".
|
|
|
|
|
That usually means that the code has been stored in the wrong folder. You should have a file named Odds.class inside your folder named weekthreeassignments. Check your build settings. As far as the actual code is concerned, it does work correctly.
|
|
|
|
|
I am interested in to see if truncating the table is actually faster than dropping and recreating it?
Does one of the write to the log?
|
|
|
|
|
There is a simple way to find the answer.
|
|
|
|
|
What did you find out when you tried both methods?
|
|
|
|
|
It may depend on things but generally speaking DROP will be faster than TRUNCATE. And TRUNCATE is faster than DELETE.
|
|
|
|
|
I would think that truncating means less "file allocation" processing (just changing a pointer?)
Dropping and recreating is essentially creating a new file / entry.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I am trying to figure out the way to invoke SQL Queries on SQL server either by using java, bash, or powershell. Is there any options to do that?
Thanks,
Azbilegt Chuluunbat
|
|
|
|
|
|
Buenos días.
Estoy siguiendo un curso en Coursera de POO en Java y en un reto de 4 preguntas, tengo solventadas 2 correctamente, pero las 2 restantes no acabo de poder con ellas.
una es la siguiente:
/**
* Método que verifica si la imagen es oscura.
* Una imagen es oscura si más del 60% de sus pixeles tienen componentes RGB menores a 10.
*/
public boolean esOscuraLaImagen()
{
}
Puede alguien ayudarme por favor. Muchas gracias.
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Estamos más que dispuestos a ayudar a aquellos que están estancados: ?pero eso no significa que estemos aquí para hacerlo todo por usted! No podemos hacer todo el trabajo, o te pagan por esto, o es parte de tus calificaciones y no sería justo que lo hiciéramos todo por ti.
Por lo tanto, necesitamos que usted haga el trabajo y lo ayudaremos cuando se quede atascado. ?Eso no significa que le daremos una solución paso a paso que puede entregar!
Comience explicando dónde se encuentra en este momento y cuál es el siguiente paso en el proceso. Luego, díganos qué ha intentado para que funcione el siguiente paso y qué sucedió cuando lo hizo.
Si tiene problemas para comenzar, esto puede ayudar: Cómo escribir código para resolver un problema, una guía para principiantes [ ^ ]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Hi and thanks for looking,
Just started to learn Java and after reading various tutorials came up with this simple tables program.
My question, is it as it should be? I mean it works OK but is it coded correctly?
import java.util.Scanner; // Import the Scanner class
public class MyTables {
public static void main(String[] args) {
int secondNum, answerNum;
Scanner sc = new Scanner(System.in); // Create a Scanner object
System.out.println("Type a number:");
secondNum = sc.nextInt(); // Read user input
for (int firstNum = 1; firstNum <= 12; firstNum ++) {
answerNum = firstNum * secondNum;
System.out.println(firstNum + " x " + secondNum + " = " + answerNum);
}
}
}
|
|
|
|
|
It looks reasonable to me. The only thing I would say is that it is generally better to start loop counters from zero, as they are often used to access array items:
for (int firstNum = 0; firstNum < 12; firstNum ++) {
answerNum = firstNum * secondNum;
System.out.println(firstNum + " x " + secondNum + " = " + answerNum);
}
Also try to use consistent indentation, as it makes your code much easier to read. I don't know which tutorials you have been working on but The Java? Tutorials[^] are some of the best for a beginner.
|
|
|
|
|
|
I have coded for Sudoku puzzle in java.The thing is my code has limitation for giving inputs for 9*9 grid. How do I make my code adaptable for all the grids.Please have patience.I am new to java.
What changes do I need to make so that the code can run on all grid sizes?The grid is square not a rectangle.
class Solution {
public void solveSudoku(char[][] board) {
if(solveSudoku2(board)) {
return;
}
}
public boolean solveSudoku2(char[][] board) {
boolean isEmpty = true;
int row = -1;
int col = -1;
int n = board.length;
for(int i = 0; i < board.length; i++) {
for(int j = 0; j < board[0].length; j++) {
if(board[i][j] == '.') {
row = i;
col = j;
isEmpty = false;
break;
}
}
if(!isEmpty) {
break;
}
}
if(isEmpty) {
return true;
}
for(int num = 1; num <= n; num++) {
char char_num = (char)(num + '0');
if(checkSafe(board,char_num,row,col)) {
board[row][col] = (char)(num + '0');
if(solveSudoku2(board)) {
return true;
} else {
board[row][col] = '.';
}
}
}
return false;
}
public boolean checkSafe(char[][] board, char num, int row, int col) {
for(int i = 0; i< board.length; i++ ) {
if(board[row][i] == num) {
return false;
}
}
for(int j = 0; j < board[0].length; j++) {
if(board[j][col] == num) {
return false;
}
}
int checknum = (int)Math.sqrt(board.length);
int startrow = row - row % checknum;
int startcol = col - col % checknum;
for(int k = startrow; k < startrow + checknum; k++) {
for(int l = startcol; l < startcol + checknum; l++) {
if(board[k][l] == num) {
return false;
}
}
}
return true;
}
}
|
|
|
|
|
Sudoku size is is limited by the values that are allowed to be placed in the squares. For digits it is 9 x 9, for alphabetics it could be any number you choose. The main problem is the complexity of the solution as the size increases.
|
|
|
|
|
package Array;
import java.util.Arrays;
public class Homework {
public static int [] sortirovka (int [] array) {
int a;
for (int i = 0; i < array.length; i++) {
int min = array [i];
int index = i;
for (int j = i + 1; j < array.length; j++) {
if (array [j] < min) {
min = array [j];
index = j;
}
}
if (i != index) {
a = array[i];
array[i]= min;
array [index] = a;
}
}
return array;
}
public static void main(String[] args) {
int [] array = {5, 2, 5, 3, 8, 9, 10, -2, 0, 6};
sortirovka (array);
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
|
|
|
|
|
Yes, quite normal, programming takes some time to learn. You can learn the basics (at your own speed) from The Java? Tutorials[^].
|
|
|
|
|
Thank you very much, appreciate it. 
|
|
|
|
|
You're welcome. Bear in mind that every 'expert' had to start learning from zero at one time.
|
|
|
|
|
Write A Program In Java That Displays A Cuckoo Clock that plays computer time
|
|
|
|
|
Nobody here will do your homework assignment for you, no matter how many times you repost it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|