Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input variable
- ''''''''''''''''''''''''''''''''''''''''''''''''
- package p1;
- import java.util.Scanner;
- public class Class1 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String str;
- System.out.print("enter your nice name : ");
- str=input.nextLine();
- System.out.println("hey "+str);
- int number;
- System.out.print("enter a number : ");
- number=input.nextInt();
- System.out.println("your number is :"+number);
- double dou;
- System.out.println("enter any double number : ");
- dou=input.nextDouble();
- System.out.println("double value : "+dou);
- }
- }
- ''''''''''''''''''''''''''''''''''''''''''''''''''''
- class + method + Constructor
- package oop;
- class box{
- int h;
- int w;
- int d;
- box(int hh ,int ww, int dd)
- {
- h=hh;
- w=ww;
- d=dd;
- }
- box()
- {
- }
- void setvalue(int hh ,int ww, int dd)
- {
- h=hh;
- w=ww;
- d=dd;
- }
- void display()
- {
- System.out.println("height = "+h);
- System.out.println("depth = "+d);
- System.out.println("weidth = "+w);
- }
- }
- public class NewClass101 {
- public static void main(String[] args) {
- box b1;// object refer
- b1= new box(); // object create
- b1.setvalue(432, 24, 324);
- // System.out.println("d ="+b1.d+" h = "+b1.h+" w = "+b1.w);
- b1.display();
- System.out.println("");
- box b2 = new box();
- b2.setvalue(2, 10, 1);
- // System.out.println("d ="+b2.d+" h = "+b2.h+" w = "+b2.w);
- b2.display();
- System.out.println("");
- box b3 = new box(1,2,3);
- b3.display();
- }
- }
Add Comment
Please, Sign In to add comment