Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class z1_23a {
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- int n;
- while (true){
- System.out.println("");
- System.out.printf("Podaj ilosc wyrazen ciagu [ > ] ");
- n = read.nextInt();
- if(n <= 0){
- System.out.println("");
- System.out.println("Podaj liczbe wieksza od 0");
- continue;
- } else {
- break;
- }
- }
- int suma = 0;
- int var = -2;
- for(int i=1; i<=n; i++){
- suma += var;
- if(var < 0){
- var*=(-1);
- var+=3;
- } else {
- var+=3;
- var*=(-1);
- }
- }
- System.out.println("");
- System.out.println("Suma = " + suma);
- read.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement