We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
not sure why this works locally but throws errors - code
import java.io.;
import java.util.;
import java.text.;
import java.math.;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in).useDelimiter("[|\n]");
String string1=sc.next();
String string2=sc.next();
int x = new Integer(string1);
int y = new Integer(string2);
if(y>0 && x>0){
System.out.println(y*x);
}else{
System.out.println("java.lang.Exception: Breadth and height must be positive");
}
}
}
errors
Solution.java:13: error: illegal start of type
if(y>0 && x>0){
^
Solution.java:13: error: expected
if(y>0 && x>0){
^
Solution.java:13: error: ';' expected
if(y>0 && x>0){
^
Solution.java:13: error: illegal start of type
if(y>0 && x>0){
^
Solution.java:13: error: ';' expected
if(y>0 && x>0){
^
Solution.java:15: error: illegal start of type
}else{
^
Solution.java:15: error: ';' expected
}else{
^
Solution.java:16: error: expected
System.out.println("java.lang.Exception: Breadth and height must be positive");
^
Solution.java:16: error: illegal start of type
System.out.println("java.lang.Exception: Breadth and height must be positive");
^
Solution.java:33: error: class, interface, or enum expected
}
^
Solution.java:34: error: class, interface, or enum expected
public static void main(String[] args){
^
Solution.java:37: error: class, interface, or enum expected
System.out.print(area);
^
Solution.java:38: error: class, interface, or enum expected
}
^
13 errors
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Static Initializer Block
You are viewing a single comment's thread. Return to all comments →
not sure why this works locally but throws errors - code import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
} errors Solution.java:13: error: illegal start of type if(y>0 && x>0){ ^ Solution.java:13: error: expected if(y>0 && x>0){ ^ Solution.java:13: error: ';' expected if(y>0 && x>0){ ^ Solution.java:13: error: illegal start of type if(y>0 && x>0){ ^ Solution.java:13: error: ';' expected if(y>0 && x>0){ ^ Solution.java:15: error: illegal start of type }else{ ^ Solution.java:15: error: ';' expected }else{ ^ Solution.java:16: error: expected System.out.println("java.lang.Exception: Breadth and height must be positive"); ^ Solution.java:16: error: illegal start of type System.out.println("java.lang.Exception: Breadth and height must be positive"); ^ Solution.java:33: error: class, interface, or enum expected } ^ Solution.java:34: error: class, interface, or enum expected public static void main(String[] args){ ^ Solution.java:37: error: class, interface, or enum expected System.out.print(area); ^ Solution.java:38: error: class, interface, or enum expected } ^ 13 errors