Advertisement
Guest User

Chapter1_Ex1

a guest
Dec 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4. /* ==================================================
  5. NoteBook chapter 1: Building stones's Language
  6.  
  7. Ex1: Circle scope & Area
  8. ==================================================
  9. */
  10. public class MyProgram {
  11. public static void main(String[] args) {
  12.  
  13. //variables
  14. int radios;
  15. float scope,area;
  16. Scanner s=new Scanner(System.in);
  17.  
  18. //user input
  19. System.out.println("Enter radios: ");
  20. radios=s.nextInt();
  21.  
  22. scope= (float) (2*radios*Math.PI); //scope: P=2*PI*R
  23. area= (float) (Math.PI * Math.pow(radios,2)); //area: S= PI*R^2
  24.  
  25. //two ways of printing
  26. System.out.println("radios: "+radios+"\tscope: "+scope+"\tarea: "+area);
  27. System.out.printf("radios: %d\tscope: %.2f\tarea: %.2f",radios,scope,area);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement