You are on page 1of 5

NAME : MOHD AZMAL SHAHFARI BIN KAMARUL ZAMAL

MATRIC ID : 21BT02014

ASSIGNMNENT 1

1. Write the complete Java program to divide a number from another

number entered by user.

import java.util.Scanner;

public class Excercise5 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner io= new Scanner (System.in);

float num1, num2, sum;

System.out.println("Please key in number 1");

num1=io.nextInt();

System.out.println("Please key in number 2");

num2=io.nextInt();

sum=num1/num2;

System.out.println("Sum of " + num1 + " divided by " + num2 + " is " + sum);

OUTPUT
2. Write the complete Java program to convert temperature value from Fahrenheit into
Celsius.

import java.util.Scanner

public class Exersice3 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner io= new Scanner (System.in);

float fahr, celc;

System.out.println("Please enter fahrenheit");

fahr=io.nextFloat();

Celc=(fahr-32)*5/9;

System.out.println("Celcius = " + celc);

OUTPUT
3. Write a program to calculate the area of a rectangular.

import java.util.Scanner;

public class Excersie1 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner io= new Scanner (System.in);

int length, breadth, sum;

System.out.println("Please key in the lenght of rectangle");

width=io.nextInt();

System.out.println("Please key in the breadth of rectangle");

Lenght=io.nextInt();

int lenght;

Sum=breadth*length;

System.out.println("The area of rectangle is " + sum);

OUPUT
4. Write a program to calculate the volume of a sphere.

import java.util.Scanner;

public class Exercise2 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner io= new Scanner (System.in);

final float PI=3.142f;

float radius, vol;

System.out.println("Please enter the radius of the sphere");

radius=io.nextFloat();

vol=(4*PI(radius*radius))/3;

System.out.println("The volume of the Sphere is " + vol );

}
5. Write a program to find the square (x2) value of an integer.

public class Exercise4 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner io=new Scanner (System.in);

int num1, Square;

System.out.println("Please key in the number");

num1=io.nextInt();

square=num1*num1;

System.out.println("The square of " + num1 + " is " + Square );

OUTPUT

You might also like