Java Saved Program: majestic-rain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
//Zad:14.Napisati programski kod koji će od korisnika tražiti unos 5 elemenata u polje realnih brojeva. Ispisati sve elemente polja. Ispisati kvadrat svakog od elemenata polja. Omogućiti unos cijelog broja x, a zatim od svakog elementa polja oduzeti x te ponovno ispisati polje.

class Script
{
    public static void main(String[] arg)
    {
        
        Scanner s = new Scanner(System.in);
        
        double[] element = new double[5];
        
        for(int i=0; i<5; i++)
        {
            System.out.println("Unesite " + (i+1) + " element:");
             element[i] = s.nextDouble();
             System.out.println(element[i] + "\n");
        
        }
        
        
        for(int i=0; i<5; i++)
        {
            System.out.println((element[i] * element[i])  + "\t");
            
        }
        
        System.out.println("Unesi broj:");
        
        int broj;
        broj = s.nextInt();
        
        for(int i=0; i<5; i++)
        {
            System.out.println(element[i] - broj + "\t");
            System.out.println(element[i] + "\n");
        }
        
    } 
    
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs