Consider the following java program:-
PROGRAM NO 1------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class calculateAreadanPerimeterofBox {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.println("Sila Masukkan nilai tinggi dan lebar segiempat!");
int tinggi = input.nextInt();
int lebar =input.nextInt();
int luasSegiempat=tinggi*lebar;
int perimeterSegiEmpat = 2*(tinggi+lebar);
System.out.println("Luas Segi Empat=" +luasSegiempat );
System.out.println("Perimeter Segi Empat=" +perimeterSegiEmpat );
}
}
PROGRAM NO 1 --------------------------------------------------------------------------------------------------
import java.util.Scanner;
class segi4{
int tinggi;
int lebar;
void getInput(){
Scanner input= new Scanner(System.in);
System.out.println("Sila Masukkan nilai tinggi dan lebar segiempat!");
tinggi = input.nextInt();
lebar =input.nextInt();
}
int kiraLuasSegiempat(){
return tinggi* lebar;
}
int kiraPerimeterSegiempat(){
return 2*(tinggi+ lebar);
}
void printOutput(){
System.out.println("Luas Segi Empat=" +kiraLuasSegiempat() );
System.out.println("Perimeter Segi Empat=" +kiraPerimeterSegiempat() );
}
}
public class calculateAreadanPerimeterofBox2 {
public static void main(String[] args) {
segi4 segiEmpat1 = new segi4();
segiEmpat1.getInput();
segiEmpat1.printOutput();
}
}
Subscribe to:
Post Comments (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
-
ANSWERS TO CHAPTER EXERCISES (CHAPTER 8) Review Questions 1. List and describe various types of output, including technolog...
-
Based on real life scenario on any local company/ organization which you are very familiar, define the problem that could be addressed thr...
-
A. Response to the following statements by circling either T (TRUE) or F (FALSE). [10M] I. 1. Java enables users...
No comments:
Post a Comment