Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Scanner in = new
- Scanner(System.in);
- int x,y;
- x = 1;
- y = 2;
- System.out.println("x = "+x);
- // error because system is written without capital
- System.out.println("y = "+y);
- System.out.println(x);
- // the thing written between the brackets without quotation is taken by its value
- System.out.println("x");
- // but within quotations its taken as it is
- System.out.println(x+y);
- String s = "x+y =";
- System.out.println(s+x+y);
- //you are adding s to x , s is a string, x is an int, so , it converts x to a string, so it's like , it created a new hidden string which contains "x + y = Value_of_x"
- // to fix this :-
- System.out.println(s+(x+y));
- // string takes anything , words / numbers , but it takes them as words, so cant be added , example :
- String num = "1";
- String bum = "2";
- System.out.println(num+bum);
- System.out.println("x + y = "+x+y);
- }
- }
- ------------------------------------------------------------------
- Scanner in = new
- Scanner(System.in);
- double x,y;
- System.out.print("x=");
- // we use the thing above to make x= appear in the function screen
- x = in.nextDouble();
- System.out.print("y=");
- y = in.nextDouble();
- System.out.println("x+y ="+(x+y));
- System.out.println("x-y ="+(x-y));
- System.out.println("x*y ="+(x*y));
- System.out.println("x/y ="+(x/y));
- }
- }
- ----------------------------------------------------------
- Scanner in = new Scanner(System.in);
- int x, y;
- System.out.print("x=");
- // we use the thing above to make x= appear in the function screen
- x = in.nextInt();
- System.out.print("y=");
- y = in.nextInt();
- System.out.println("x+y =" + (x + y));
- System.out.println("x-y =" + (x - y));
- System.out.println("x*y =" + (x * y));
- /*
- * if (y == 0) { System.out.println("x/y =" + " infinity " ); // u can
- * type "x/y = infinity " instead // division line here }
- *
- * else { System.out.println("x/y =" + x/y);
- *
- * }
- */
- if (y == 0) {
- System.out.println("x/y = infinity");
- }
- if (y != 0) {
- System.out.println("x/y =" + x / y);
- }
- // System.out.println(0.1+0.2);
- // fun line :P
- // System.out.println(5/0);
- }
- }
- ------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement