write java prgram

write java prgram

write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation.

View Answers

May 25, 2012 at 5:24 PM

import java.util.Scanner;

public class CalculateAreaOfShapes{
    public static void main(String []args){
        int choice;
        Scanner scanner=new Scanner(System.in);
        System.out.println("1.For circle area.");
        System.out.println("2.For square area ");
        System.out.println("3.For Rectangle area");
        System.out.println("Input your choice : ");
        choice=scanner.nextInt();
        switch(choice){
        case 1: System.out.println("Input radius of circle : ");
                float radius=scanner.nextFloat();
                float pi=(float) 3.14;
                float area=pi*radius*radius;
                System.out.println("Area of circle = "+area);
                break;
        case 2:System.out.println("Input side of square : ");
                float length=scanner.nextFloat();
                area=length*length;
                System.out.println("Area of your square = "+area);
                break;
        case 3:System.out.println("Input length of rectangle : ");
               length =scanner.nextFloat();
               System.out.println("Input width of rectangle : ");
               float width=scanner.nextFloat();
               area=length*width;
               System.out.println("Area of rectangle = "+area);
               break;
        default: System.out.println("Your choice is not correct.");       
        }
    }
}

Description :Here we are calculating area of 3 shapes according to user choice. If user input 1 then we calculate circle area as Formula

area of circle=3.14*radius*radius

If User's choice is 2 then your program give you output of square area. Formula of square-

area of Square=length*width; where length and width are same

If choice is 3 then it will generate area of rectangle.Formula is -

Area of rectangle = length*width .









Related Tutorials/Questions & Answers:
write java prgram
write java prgram  write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation
write a java program
write a java program  write a program to print '*' in a circular form
Advertisements
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
write a programm using java
write a programm using java  print the following using java programming
Java write to file
Java write to file  How to write to a file in Java? Is there any good example code here? Thanks   Hi, Java is one of the best... files. You can easily use the the FileWriter and BufferedWriter to write data
write the java program?
write the java program?  1 11 121 1331 14641 15101051
write the java program?
write the java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... to write in File of Java Program... the (BufferedReader) constructor. So that we write some data suing
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
How to Write to file in Java?
How to Write to file in Java?  How to Write to file in Java Program?   Hi, For writing a file in Java, we need some classes from Java.IO... the Examples of How to write to File in Java Program: WriteToFileExample.java import
Write a program in java...
Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two... to enter an integer number. Write a program in java to find the factorial
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  How do I write a program in Java, have the program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  Write program which accepts five students id,name,age,department,courses, taken and its grade. a. calculate its GPA . display all student information in ascending order
write program - Java Beginners
write program  write a java program that will read the values...]); } System.out.println(); } } } For more information on java visit to : http://www.roseindia.net/java/beginners/ Thanks
Write short note on Java package.
Write short note on Java package.  Write short note on Java package
write a program - Java Beginners
write a program  1. write a program that reads a string composed of 6 words then generate and print a word composed of the first letters of the 6 words.  Hi friend, Code to solve the problem : class FirstLetter
write a program in java.
write a program in java.  arrange the natural n umber in 5x5 matrix as 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 i at centerd position and remaining arrange in anticlockwise direction.  
Java Stream Write Exception
Java Stream Write Exception  I am doing socket programming. I have two files called Server.java and client.java. Both programs were running successfully and successfully sending data to each other. Yesterday I added the following
How to Write To File BufferedWriter in Java
How to Write To File BufferedWriter in Java  how to write to file bufferedwriter in Java   In Java there are 2 types of class files used... to write texts. In this classwe stores the character in a buffer to write
how to write java data - XML
how to write java data  how to write data to xml file  Hi friend, Read for more information, http://www.roseindia.net/xml/dom/ Thanks
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
how to write append file in Java
how to write append file in Java  How to write append file in Java... existing file should be retained when you are trying to write new contents in an existing files. For this in java program we uses WriteToFileAppend.java to be used
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file in Java   Hi, To create Comma separated value(CSV) file is very simple... passed the file name to write into a stream characters. Then we use the FileWriter
Java Write to File
Java Write to File In this tutorial you will learn how to write to file in java. Write to a file in java we are required to use some classes of java.io... stores the characters in a buffer to write into a character-output stream
Write a java pregram: Help with methods
Write a java pregram: Help with methods  Write a Java method that returns the number of days in a year using the following header: public static int numberOfDaysInAYear (int year) Write a Java program that uses your method
CREATE AND WRITE FILE THREAD JAVA
CREATE AND WRITE FILE THREAD JAVA  Hi guys I was wondering how can I make this program in java with threads. I need to create a file and write in it (i know how to do that) but by listening in some port all the data that is being
Java file read write operation
Java file read write operation  how to read and write the data from..."); oos.writeInt(8000); oos.writeObject("Ankit"); oos.writeObject("Java..."+sal1); for complete tutorial you can follow this link Java ObjectOutputStream
How to write a simple java applet
How to write a simple java applet   Hi, how can i write a simple java applet, displaying text in specific colors and font style. For example, the output will be something like : Name in red color Age in blue color Nationality
Write a Java applet to draw cylinder and pentagon shapes.
Write a Java applet to draw cylinder and pentagon shapes.  Write a Java applet to draw cylinder and pentagon shapes
read/write to Windows Registry using Java
read/write to Windows Registry using Java  read/write to Windows Registry using Java
how to write this program? - Java Beginners
how to write this program?  (game:scissor,rock ,paper) A program that plays the sciccor-rock-paper game.Revise the program to let the user continuously play until either the user or the computer wins more than 4 times
Java Write To File - Java Tutorial
Java Write To File - Java Tutorial Learn how to write to a file from Java... on a FileOutputStream classes to write data to a file from Java program... Tutorial you will learn how to write java program to write to a file. We will use
how to write the program - Java Beginners
how to write the program  WAP to create the report card user input Name, Class, Division, Roll no., Marks obtained in following subjects Lang Hindi History Geography Math Phy Chem. Bio Eve CSTA Also has a back up
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
How to write in Binary file in Java programming language
How to write in Binary file in Java programming language  I need some help about Java programming. Please explain me "How to write in Binary file in Java programming language
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
What is the best way to write to file in Java?
What is the best way to write to file in Java?  I am creating... to write to a text file in Java? Since my program will continuously write the data...;Read the tutorial at Java Write To File - Java Tutorial. Thanks
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java programming. Thanks,   Hi, Are you eager to learn how to write to file from
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java... to a file from Java program. To write the Java Write To File we will use two... and execute it, this will write "Hello Java" into out.txt file. While creating
Java Write To File - Java Tutorial
of OutputStreamWriter class that is used to write text (as opposed to binary data... an internal FileOutputStream to write bytes to the specified fileADS_TO_REPLACE_1 BufferedWriter : The BufferedWriter class is used to write
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
How to write file from inputstream in java
link to your query "How to Write to inputStream in Java". This is good...How to write file from inputstream in java  Hi, how to write file from inputstream in java program. Plz suggest an example or suggested link
Java Write To InputStream
Java Write To InputStream In this tutorial you will learn how to write to InputStream in java. Write to file from InputStream in java you may use... the basic process to execute a java program write simply on command prompt
How to write a file in Java?
How to write a file in Java? To write a file in Java use the class FileWriter and BufferedWriter. Class FileWriter: The FileWriter class is used to write... and strings. Example of how to write text to a file in java:ADS_TO_REPLACE_6 import

Ads