Created
April 23, 2024 02:29
-
-
Save PramodDutta/33ce998bdf9382c80ca3654bee1da315 to your computer and use it in GitHub Desktop.
Problem with the Java pROGRAM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package src.ex_23042024; | |
import java.util.Scanner; | |
public class Lab079 { | |
public static void main(String[] args) { | |
//✅ Triangle Classifier: | |
// | |
// Write a program that classifies a triangle based on its side lengths. | |
// Given three input values representing the lengths of the sides, determine | |
// if the triangle is equilateral (all sides are equal), | |
// isosceles (exactly two sides are equal), or | |
// scalene (no sides are equal). | |
// Use an if-else statement to classify the triangle. | |
// side1, side2, side3 -> | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter the side1,side2,side3, I will tell about the triangle"); | |
int side1 = sc.nextInt(); | |
int side2 = sc.nextInt(); | |
int side3 = sc.nextInt(); | |
// = Assign the value | |
// == compare the values | |
if((side1 == side2) && (side1 == side3) && (side2 == side3)){ | |
System.out.println("EQ"); | |
}else if((side1 == side2) || (side1 == side3) || (side2 == side3)){ | |
System.out.println("ISO"); | |
}else{ | |
System.out.println("Scalene!"); | |
} | |
} | |
} |
My program is not running. It is giving below error
error1 "class PositiveNegativeChecker is public, should be declared in a file named PositiveNegativeChecker.java"
error2 "cannot find symbol variable sc"
My Code:
package JavaBasicCodes;
import java.util.Scanner;
public class PositiveNegativeChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number: ");
int num = sc.nextInt();
PNChecker(num);
}
public static void PNChecker(int num){
if (num >= 1){
System.out.println("Positive Number");
}else if (num < 0){
System.out.println("Negative Number");
}else {
System.out.println("Zero");
sc.close();
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to fix this issue?