Advertisement
CR7CR7

taskFruits

Mar 9th, 2023
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Task3 {
  4.     public static void main(String[] args) {
  5.         Scanner sc =new Scanner(System.in);
  6.         int countBox=Integer.parseInt(sc.nextLine());
  7.         int k=1;
  8.         int smallestBox=1;
  9.         smallestBox =k;
  10.         int nextOne =k*(k+1);
  11.         int countOrange=0;
  12.         int countApple=0;
  13.        
  14.         for (int i=0;i<=countBox;i++){
  15.             if(i%2==0){
  16.                 countOrange+=nextOne;
  17.             }
  18.             if(i%2!=0){
  19.                 countApple+=smallestBox;
  20.             }
  21.            
  22.         }
  23.        
  24.  
  25.         System.out.println(Math.abs(countOrange-countApple));
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement