Java Assigment Basics

Submitted by: Submitted by

Views: 60

Words: 487

Pages: 2

Category: Science and Technology

Date Submitted: 11/13/2014 09:41 PM

Report This Essay

Assignment # 1

1:Write a program to display "Hello Computer" on the screen. And then explain the working mechanism, and execution of the program.

public class HelloComputer {

public static void main(String[] args) {

System.out.println("Hello Computer");

}

}Working

In this program I declair a class HelloComputer. A method is used to print desired sting public static void main(String[] args). The compiler execute the println and result Hello Computer.

______________________________________________________________________________________

Write a program to display Your Name, Address and City in different lines.

public class Name {

public static void main(String[] args) {

System.out.println("ASAD BAIG");

System.out.println("MOH. SARDARPURA SARGODHA ROAD GUJRAT");

System.out.println("GUJRAT");

}

}__________________________________________________________________________________

Write a program to find the area of a circle using the formula: Area = PI * r2

import java.util.Scanner;

public class Area {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double radius;

System.out.println("Enter the Radius of Circle? ");

radius = sc.nextDouble();

double PI = 3.14;

double Area = PI * radius * radius;

System.out.println(Area);

}

}_____________________________________________________________________________________

Write a program to find the area and volume of sphere. Formulas are:

Area = 4*PI*R*R Volume = 4/3*PI*R*R*R.

import java.util.Scanner;

public class Area {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double radius;

System.out.println("Enter the Radius...