Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1.    {
  2.         Scanner in = new
  3.         Scanner(System.in);
  4.         int x,y;
  5.         x = 1;
  6.         y = 2;
  7.         System.out.println("x = "+x);
  8.         // error because system is written without capital
  9.         System.out.println("y = "+y);
  10.         System.out.println(x);
  11.         // the thing written between the brackets without quotation is taken by its value
  12.         System.out.println("x");
  13.         // but within quotations its taken as it is
  14.         System.out.println(x+y);
  15.        
  16.         String s = "x+y =";
  17.         System.out.println(s+x+y);
  18.         //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"
  19.         // to fix this :-
  20.         System.out.println(s+(x+y));
  21.         // string takes anything , words / numbers , but it takes them as words, so cant be added , example :
  22.         String num = "1";
  23.         String bum = "2";
  24.         System.out.println(num+bum);
  25.         System.out.println("x + y = "+x+y);
  26.        }
  27.    
  28.    
  29.    
  30.    
  31. }
  32. ------------------------------------------------------------------
  33. Scanner in = new
  34.         Scanner(System.in);
  35.        
  36.         double x,y;
  37.        
  38.         System.out.print("x=");
  39.         // we use the thing above to make x= appear in the function screen
  40.         x = in.nextDouble();
  41.        
  42.         System.out.print("y=");
  43.         y = in.nextDouble();
  44.        
  45.        
  46.         System.out.println("x+y ="+(x+y));
  47.        
  48.         System.out.println("x-y ="+(x-y));
  49.        
  50.         System.out.println("x*y ="+(x*y));
  51.        
  52.         System.out.println("x/y ="+(x/y));
  53.     }
  54. }
  55. ----------------------------------------------------------
  56.  
  57.         Scanner in = new Scanner(System.in);
  58.  
  59.         int x, y;
  60.  
  61.         System.out.print("x=");
  62.         // we use the thing above to make x= appear in the function screen
  63.         x = in.nextInt();
  64.  
  65.         System.out.print("y=");
  66.         y = in.nextInt();
  67.  
  68.         System.out.println("x+y =" + (x + y));
  69.  
  70.         System.out.println("x-y =" + (x - y));
  71.  
  72.         System.out.println("x*y =" + (x * y));
  73.  
  74.         /*
  75.          * if (y == 0) { System.out.println("x/y =" + " infinity " ); // u can
  76.          * type "x/y = infinity " instead // division line here }
  77.          *
  78.          * else { System.out.println("x/y =" + x/y);
  79.          *
  80.          * }
  81.          */
  82.  
  83.         if (y == 0) {
  84.             System.out.println("x/y = infinity");
  85.         }
  86.         if (y != 0) {
  87.             System.out.println("x/y =" + x / y);
  88.         }
  89.  
  90.         // System.out.println(0.1+0.2);
  91.         // fun line :P
  92.         // System.out.println(5/0);
  93.  
  94.     }
  95. }
  96. ------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement