Falak_Ahmed_Shakib

java code

Sep 9th, 2021 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. input variable
  2.  
  3.  
  4. ''''''''''''''''''''''''''''''''''''''''''''''''
  5.  
  6. package p1;
  7. import java.util.Scanner;
  8.  
  9.  
  10.  
  11. public class Class1 {
  12.  
  13. public static void main(String[] args) {
  14.  
  15.  
  16. Scanner input = new Scanner(System.in);
  17. String str;
  18. System.out.print("enter your nice name : ");
  19. str=input.nextLine();
  20. System.out.println("hey "+str);
  21.  
  22. int number;
  23. System.out.print("enter a number : ");
  24. number=input.nextInt();
  25. System.out.println("your number is :"+number);
  26.  
  27.  
  28. double dou;
  29. System.out.println("enter any double number : ");
  30. dou=input.nextDouble();
  31. System.out.println("double value : "+dou);
  32.  
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. }
  43. ''''''''''''''''''''''''''''''''''''''''''''''''''''
  44.  
  45.  
  46. class + method + Constructor
  47.  
  48.  
  49.  
  50. package oop;
  51.  
  52. class box{
  53.  
  54. int h;
  55. int w;
  56. int d;
  57.  
  58.  
  59. box(int hh ,int ww, int dd)
  60. {
  61. h=hh;
  62. w=ww;
  63. d=dd;
  64. }
  65.  
  66. box()
  67. {
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void setvalue(int hh ,int ww, int dd)
  74. {
  75. h=hh;
  76. w=ww;
  77. d=dd;
  78. }
  79.  
  80.  
  81. void display()
  82. {
  83. System.out.println("height = "+h);
  84. System.out.println("depth = "+d);
  85. System.out.println("weidth = "+w);
  86. }
  87.  
  88. }
  89.  
  90. public class NewClass101 {
  91.  
  92. public static void main(String[] args) {
  93.  
  94. box b1;// object refer
  95. b1= new box(); // object create
  96.  
  97. b1.setvalue(432, 24, 324);
  98.  
  99. // System.out.println("d ="+b1.d+" h = "+b1.h+" w = "+b1.w);
  100.  
  101. b1.display();
  102.  
  103. System.out.println("");
  104. box b2 = new box();
  105.  
  106. b2.setvalue(2, 10, 1);
  107.  
  108. // System.out.println("d ="+b2.d+" h = "+b2.h+" w = "+b2.w);
  109. b2.display();
  110.  
  111. System.out.println("");
  112. box b3 = new box(1,2,3);
  113. b3.display();
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
Add Comment
Please, Sign In to add comment