xxxxxxxxxx
#include <stdio.h>
#include <stdbool.h>
void e1(int lignes, int colonnes, int **mat, bool *pe, int *resultat) {
*pe = false;
for (int r = 0; r < lignes; r++) {
bool pair = true;
for (int c = 0; c < colonnes; c++) {
if (mat[r][c] % 2 != 0) {
pair = false;
break;
}
}
if (pair) {
*pe = true;
for (int c = 0; c < colonnes; c += 2) {
mat[r][c] = 1;
}
break;
}
}
*resultat = *pe ? 1 : 0;
}
int main() {
int lignes = 3;
int colonnes = 4;
int *mat = (int *)malloc(lignes * sizeof(int *));
for (int i = 0; i < lignes; i++) {
mat[i] = (int *)malloc(colonnes * sizeof(int));
}
for (int i = 0; i < lignes; i++) {
for (int j = 0; j < colonnes; j++) {
mat[i][j] = i * colonnes + j + 1;
}
}
bool pe;
int resultat;
e1(lignes, colonnes, mat, &pe, &resultat);
if (pe) {
printf("La valeur de 'pe' est true et les éléments d'une ligne ont été modifiés.\n");
} else {
printf("La valeur de 'pe' est false et aucune ligne avec tous les éléments pairs n'a été trouvée.\n");
}
printf("La valeur de 'resultat' est: %d\n", resultat);
for (int i = 0; i < lignes; i++) {
free(mat[i]);
}
free(mat);
return 0;
}
xxxxxxxxxx
//well, that means that ur main method doesn't exist, or your main method is out of your class.
//so, keep focusing in bracing part.
//main method should be like this:
Class main{
public static void main(String[] args) {
//ur code
}
}
//hopefully this can help u :D
xxxxxxxxxx
// Your class `YourClass`
public class YourClass {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
// In terminal
$ java YourClass // Error Could not find or load main class YourClass
// likely bc your class file has a typo or doesn't exist.
// ergo
$ javac YourClass.java // Creates your class file in the same folder as your java file
$ java YourClass // Executes your java prorgram successfully
xxxxxxxxxx
public class MainClass {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
xxxxxxxxxx
The main() method is required to run/execute programs developed in the Java programming language since it is where the program execution begins. When starting a Java program, you could encounter the warning “error: Could not find or load main class.” You’re having this problem because you’re using the java command to run main() from within the class.