Problem with my Java code

Hi,
I have a problem with my Java code for the program that I have written.It
shows an error saying "Invalid method declaration;return type required;".
Please help.Thanks.

[code]import java.io.*;
class rini1
{
public static long perimeter_rectangle(int l,int b)
{
long x=2*(l=b);
System.out.println(x);
System.out.println(a);
return x;
}
public static long perimeter_square(int s)
{
long a=4*s;
return a;
}

public static void main(String args[])throws IOException;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
{
System.out.println("1=perimeter of rectangle");
System.out.println("2=perimeter of square");
System.out.println("ENTER YOUR CHOICE");
}

String str=br.readLine();
int S=Integer.parseInt(str);
Switch(S); //Error found at this point
{
case1:
{
System.out.println("enter the length n breadth");
String l=br.readLine();
int z=Integer.parseInt(l);
String b=br.readline();
int q=Integer.parseInt(b);
long x=perimeter_rectangle(a,c);

break;
}
case2:
{
System.out.println("enter d side");
String s=br.readLine();
int q=Integer.parseInt(s);
long a=perimeter_square(q);

break;
}
Default:
System.out.println("INVALID CHOICE");
}
}[/code]

Comments

  • import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    class rini1 {
    public static long perimeter_rectangle(int l, int b) {
    long x = 2 * (l + b);
    System.out.println(x);
    // System.out.println(a);
    return x;
    }

    public static long perimeter_square(int s) {
    long a = 4 * s;
    return a;
    }

    public static void main(String args[])throws IOException
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("1=perimeter of rectangle");
    System.out.println("2=perimeter of square");
    System.out.println("ENTER YOUR CHOICE");


    String str=br.readLine();
    int S=Integer.parseInt(str);
    switch(S) //Error found at this point
    {
    case 1:
    {
    System.out.println("enter the length n breadth");
    String l=br.readLine();
    int z=Integer.parseInt(l);
    String b=br.readLine();
    int q=Integer.parseInt(b);
    long x=perimeter_rectangle(z,q);

    break;
    }
    case 2:
    {
    System.out.println("enter d side");
    String s=br.readLine();
    int q=Integer.parseInt(s);
    long a=perimeter_square(q);

    break;
    }
    default:
    System.out.println("INVALID CHOICE");
    }
    }
    }

  • import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    class rini1 {
    public static long perimeter_rectangle(int l, int b) {
    long x = 2 * (l = b);
    System.out.println(x);
    // System.out.println(a);
    return x;
    }

    public static long perimeter_square(int s) {
    long a = 4 * s;
    return a;
    }

    public static void main(String args[])throws IOException
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("1=perimeter of rectangle");
    System.out.println("2=perimeter of square");
    System.out.println("ENTER YOUR CHOICE");


    String str=br.readLine();
    int S=Integer.parseInt(str);
    switch(S) //Error found at this point
    {
    case 1:
    {
    System.out.println("enter the length n breadth");
    String l=br.readLine();
    int z=Integer.parseInt(l);
    String b=br.readLine();
    int q=Integer.parseInt(b);
    long x=perimeter_rectangle(z,q);

    break;
    }
    case 2:
    {
    System.out.println("enter d side");
    String s=br.readLine();
    int q=Integer.parseInt(s);
    long a=perimeter_square(q);

    break;
    }
    default:
    System.out.println("INVALID CHOICE");
    }
    }
    }

  • import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    class rini1 {
    public static long perimeter_rectangle(int l, int b) {
    long x = 2 * (l = b);
    System.out.println(x);
    // System.out.println(a);
    return x;
    }

    public static long perimeter_square(int s) {
    long a = 4 * s;
    return a;
    }

    public static void main(String args[])throws IOException
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    System.out.println("1=perimeter of rectangle");
    System.out.println("2=perimeter of square");
    System.out.println("ENTER YOUR CHOICE");


    String str=br.readLine();
    int S=Integer.parseInt(str);
    switch(S) //Error found at this point
    {
    case 1:
    {
    System.out.println("enter the length n breadth");
    String l=br.readLine();
    int z=Integer.parseInt(l);
    String b=br.readLine();
    int q=Integer.parseInt(b);
    long x=perimeter_rectangle(z,q);

    break;
    }
    case 2:
    {
    System.out.println("enter d side");
    String s=br.readLine();
    int q=Integer.parseInt(s);
    long a=perimeter_square(q);

    break;
    }
    default:
    System.out.println("INVALID CHOICE");
    }
    }
    }
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion