Results 1 to 4 of 4
  1. #1
    SupaStudy is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default Errors in Program (Right Triangle)

    hey everyone, new to Java but I'm really really enjoying it. I'm having some issues though, and I know they are probably silly ones, but I cant seem to figure out how to fix it.

    The book im using to learn gives examples of TerminalIO, but I've been using java.util.scanner. Below is a program that when entering three side lengths will tell you if the triangle is a right triangle. Here is my program:


    Java Code:
     	import java.util.Scanner;
    //=====================================================================
    public class project4_2 {
    //=====================================================================
    	private static Scanner keyboard = new Scanner (System.in);
    	
    
    	//INPUT=============================================================
    		//===============================================================
    			private static void main (String[] args){
    				double side1, side2, side3;
    				
    			//----User Input	
    				System.out.println(" ");
    				side1 = reader.readDouble("Enter First Side Length: ");
    				side2 = reader.readDouble("Enter Second Side Length: ");
    				side3 = reader.readDouble("Enter Third Side Length: ");
    				
    			//----Compute
    				findSideOrder(side1, side2, side3);
    				
    			}
    		
    		
    	//PROCESSING/OUTPUT=================================================
    		//===============================================================
    			private static double findSideOrder(double side1, double side2, double side3);{
    						
    				if ((side1 * side1) + (side2 * side2) = (side3 * side3))
    					System.out.println("The Triangle is a Right Triangle");
    				else if ((side2 * side2) + (side3 * side3) = (side1 * side1))
    					System.out.println("The Triangle is a Right Triangle");
    				else if ((side1 * side1) + (side3 * side3) = (side2 * side2))
    					System.out.println("The Triangle is a Right Triangle");
    				else
    					System.out.println("The Triangle is Not a Right Triangle");
    			}
     		}

    the error i am receiving is...
    project4_2.java:15: cannot find symbol
    symbol : method readDouble(java.lang.String)
    location: class java.util.Scanner
    Last edited by SupaStudy; 03-26-2009 at 11:16 AM. Reason: put program in code brackets

  2. #2
    faisalcmpm is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    There is no method readDouble in java.util.Scanner.

    U can go for nextDouble() instead

  3. #3
    mrbharatmehta is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    You should be writing the code like:
    Java Code:
    import java.util.Scanner;
    
    //=====================================================================
    public class project4_2 {
    	//=====================================================================
    	private static Scanner reader = new Scanner (System.in);
    	
    	public  static void main (String[] args){
    		double side1, side2, side3;
    
    		//----User Input	
    		System.out.println("Enter First Side ");
    		side1 = reader.nextDouble();
    		System.out.println("Enter Second Side ");
    		side2 = reader.nextDouble();
    		System.out.println("Enter Third Side ");
    		side3 = reader.nextDouble();				
    		//----Compute
    		findSideOrder(side1, side2, side3);
    
    	}
    
    
    	//PROCESSING/OUTPUT=================================================
    	//===============================================================
    	private static void findSideOrder(double side1, double side2, double side3){
    
    		if ((Math.pow(side1, 2) + Math.pow(side2, 2)) == Math.pow(side3, 2))
    			System.out.println("The Triangle is a Right Triangle");
    		else if ((Math.pow(side3, 2) + Math.pow(side2, 2)) == Math.pow(side1, 2))
    			System.out.println("The Triangle is a Right Triangle");
    		else if ((Math.pow(side3, 2) + Math.pow(side1, 2)) == Math.pow(side2, 2))
    			System.out.println("The Triangle is a Right Triangle");
    		else
    			System.out.println("The Triangle is Not a Right Triangle");
    	}
    }

  4. #4
    mrbharatmehta is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    And if you want the JVM to find your main method, please mark that as public. Also we can use the methods supplied by the Math class to perform the square operation.

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2009, 02:51 AM
  2. Replies: 5
    Last Post: 02-04-2009, 02:20 AM
  3. Triangle Sides program
    By jamesov89 in forum New To Java
    Replies: 6
    Last Post: 10-06-2008, 04:36 AM
  4. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-09-2008, 12:49 AM
  5. 3 errors and then terminate program
    By hezfast2 in forum New To Java
    Replies: 2
    Last Post: 05-20-2008, 02:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •