ok, i been tryin to get my head around this all weekend but im useless at it. i have the sollution but its saved to my laptop which i left in uni and is now missing!! but im trying to write a program which allows the user to input 3 integers representing angles of a triangle. the java program then outputs wether its an isosceles, rightangled or equalateral triangle. the output i understand. its the user input that i cant get to work. im using Jcreator pro and using "getScannerInput.anInt........" but it wont work!! i would be forever grateful if some1 could help me out wit the script, and i wud finally be able to get some sleep
cheers

Why don't you use javax.swing.JOptionPane.showInputDialog(...)
That takes in a String, then you can just parse it to an int, using
int x=Integer.parseInt(someString);

You don't need to input the 3 angles, any 2 will do, then just get program to work out the 3rd.

>getScannerInput.anInt

yes there is nothing like this in Java classes. You better check what options you best to use in JAVA APIdocumenation

I usauly do it like this

Scanner input = new Scanner(System.in);
int num1 = input.nextInt();
int num2 = input.nextInt();

dont forget

import java.util.*;
or
import java.util.Scanner;

thanks for all the help thus far guys. i now got the following code but it says "class" or "interface" expected for the last line??? any help??

import java.util.Scanner;

 public class triangles1
{
    public static void main(String [] args)
    {
    Scanner input = new Scanner(System.in);
int ang_1 = input.nextInt();
int ang_2 = input.nextInt();
int ang_3 = input.nextInt();
    int total = ang_1+ang_2+ang_3;
    {
        if(total!=180)
        System.out.println("please re-enter angles so as they equal 180");
        }
{
if(ang_1==90||ang_2==90||ang_3==90)
System.out.println("right triangle");
}
{
if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1))
System.out.println("isosceles triangle");
}
{
if(ang_1==ang_2&&ang_2==ang_3)
System.out.println("equilateral triangle");
    }

}}}// end class

Edited 3 Years Ago by pyTony: fixed formatting

Comments
Right question get fast response, he know it :-)

you put your braclets in wrong place, opening bracked before if statement, plus you had extra bracklet on the end. Also you don't have to do if this do this, if this do that, use else if or switch. But I belive you going by book so you get there. For future use code tag for pasting code( the # character)

import java.util.Scanner;

public class triangles1
{
	public static void main(String [] args)
	{
		Scanner input = new Scanner(System.in);
		int ang_1 = input.nextInt();
		int ang_2 = input.nextInt();
		int ang_3 = input.nextInt();
		int total = ang_1+ang_2+ang_3;

		if(total!=180)
		{
			System.out.println("please re-enter angles so as they equal 180");
		}
	
		else if(ang_1==90||ang_2==90||ang_3==90)
		{
			System.out.println("right triangle");
		}
	
		else if((ang_1==ang_2&&ang_1!=ang_3)||(ang_1==ang_3&&ang_1!=ang_2)||(ang_2==ang_3&&ang_2!=ang_1))
		{
			System.out.println("isosceles triangle");
		}
		
		else if(ang_1==ang_2&&ang_2==ang_3)
		{
			System.out.println("equilateral triangle");
		}
	}
}// end class

I use sometimes JCreator, but now more NetBeans because of uni project, but you can switch auto bracklets in the "OPTIONS/EDITOR/JAVA/COMPATIBILITY/ uncheck Auto insert bracklet"
Well that what i did with my one, i don't like to do extra check for bracklets if I try some example from books/internet

Good luck with your study of JAVA :cheesy:

This article has been dead for over six months. Start a new discussion instead.