7/05/2017
BCS2233 OOP. LAB Array and GUI
1. Read ten numbers, compute their average, and find out how many numbers are above the average.
Answers
import java.util.Scanner;
public class demoArray1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double[] arrayNum = new double[10];
int i,moreThanAvg;
double num,sum,avg;
sum=0;
moreThanAvg=0;
System.out.println("Input 10 Numbers ");
for(i=0;i<=9;i++){
num= input.nextDouble();
arrayNum[i]=num;
sum = sum +num;
}
avg=sum/10;
System.out.println("Sum of 10 numbers ="+sum);
System.out.println("Average of 10 numbers="+avg);
for(i=0;i<=9;i++){
if (arrayNum[i]>avg)
moreThanAvg++;
}
System.out.println("Total of number above average ="+moreThanAvg);
}
}
2. Write a program statement that will do the following of array N as shown below:-
int[] arrayN = new int[10];
for(i=0;i<=9;i++){
arrayN[i]=i+1;
}
i) Print first element.
ii) Print last element.
iii) Print all elements (use loop).
iv) Replace third element with 5.
v) Replace last element with 100;
vi) Copy the elements in the fifth location into the first one.
vii) Increase the sixth element by 10.
viii) Decrease the second element by 1;
ix) Sum and print all elements.
x) Print only odd element(s).
3. Show output of the following java program.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class MyJavaFX extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a button and place it in the scene
Button btOK = new Button("OK");
Scene scene = new Scene(btOK, 200, 300);
primaryStage.setTitle("My First GUI"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
public static void main(String[] args) {
launch();
}
}
4. Write a java program to print the following output:
Subscribe to:
Post Comments (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
-
ANSWERS TO CHAPTER EXERCISES (CHAPTER 8) Review Questions 1. List and describe various types of output, including technolog...
-
Based on real life scenario on any local company/ organization which you are very familiar, define the problem that could be addressed thr...
-
A. Response to the following statements by circling either T (TRUE) or F (FALSE). [10M] I. 1. Java enables users...
No comments:
Post a Comment