Compilation error in java [closed] - java

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 8 years ago.
Improve this question
This code works in Eclipse, but when I try to submit the 'Test' problem on the SPOJ site, it gives me a compilation error.
Can you please tell me why?
public class Test{
public static void main(String [] args)
{
java.util.Scanner input=new java.util.Scanner(System.in) ;
int n ;
while(true )
{
n =input.nextInt() ;
if(n==42)
break ;
else
System.out.println(n) ;
}
}
}

You have to name your class "Main" for it to work on SPOJ.
See this forum post for more information: https://www.spoj.com/forum/viewtopic.php?t=37

Related

Java - Unresolved Compilation Problem creating multiple classes within a single file [closed]

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 3 days ago.
Improve this question
I'm new at Java, and I'm practicing creating different classes within the same file, and them using them as objects. But when it compiled, it gives me an error on line 07. This is my code so far:
import java.util.Scanner;
package functions;
public class functions {
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
functions fun = new functions();
fun.Print("Hello World");
}
public void Print(String text) {
System.out.print(text);
}
}
The error in question is:
Exception in thread "main" java.lang.Error: Unresolved compilation
problem: at functions.functions.main
I've tried to delete any class that were not main, I've tried to create the file without a package.
The package declaration should come before the import.

Error: Could not find or load main class CountRows? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Please suggest How can I improve my question
I ran my code but it throws cannot find main class error. I know this error comes when name of class with main method is different from file name. I tried to solve this error for an hour. I need help.
CountRows.java
import java.io.*;
import java.sql.*;
public class CountRows
{
public static void main(String args[])
{
System.out.println("Count number of rows in a specific table!");
Connection con = null;
int count = 0;
try
{
//Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial","root","dics");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Execution
>javac -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows.java
E:\user\java\jdbc\test>java -classpath "e:\softwares\java\jar files\mysql-connector-java-8.0.19.jar" CountRows
Error: Could not find or load main class CountRows
Edit: Although the solution works but I still don't understand what was wrong with my way of executing code
Your Code is working perfectly fine there is no issue in it.
I suggest you set classpath initially before using javac and java tools.
Set your classpath via CMD
set classpath="<EXTERNAL_JAR_FILES_PATH>"
I hope this might help you. If you are still facing the same issue you can ping me back. I will be happy to help you.

Keep getting error in JAVA [closed]

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 8 years ago.
Improve this question
I keep getting this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at test.apples.main(apples.java:6)
My code is:
import java.util.Random;
class apples {
public static void main(String args[]) {
Random rand = new Random();
int freq[]=new int[7];
for(int roll=1;roll<1000;roll++) {
++freq[1+rand.nextInt(6)];
}
System.out.println("Face\tFrequency");
for(int face=1;face<freq.length;face++) {
System.out.println(face+"\t" +freq[face]);
}
}
}
You have to add package test; at the top of you class, then clean and rebuild your code.

trying to run a loop in java with below code who gives output a - b c- d but getting error package Sytem does not found? [closed]

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 8 years ago.
Improve this question
getting two error when trying to compile programm using commandline
error-Shuffle1.java:24 error:package System does not exist
System.out.print("b c")
Shuffle1.java:31 error:package System does not exist
System.out.print("b c")
letter in word Sytem is also capital then too getting error
public class Shuffle1
{
public static void main(String[] args)
{
int x=3;
while(x > 0){
if(x > 2){
System.out.print("a");
}
x=x-1;
System.out.print("-");
if(x==2){
Sytem.out.print("b,c");
}
if(x==1){
Sytem.out.print("d");
x=x-1;
}
}
}
}
It is
System.out.print
NOT
Sytem.out.print
Cause you wrote Sytem instead System

How can I run files in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I run a file (like an exe program) using java? I have searched up how to open a file (even on oracle docs) to no avail. Is there a class to help me with this? I tried
try
{
Runtime rt = Runtime.getRuntime() ;
Process p => rt.exec("Program.exe") ;
InputStream in = p.getInputStream() ;
OutputStream out = p.getOutputStream ();
InputSream err = p.getErrorStream() ;
p.destroy() ;
}
catch(Exception exc)
{
}
But it didn't work
Try this
Runtime.getRuntime().exec("c:\\program files\\test\\test.exe", null, new File("c:\\program files\\test\\"));

Categories

Resources