Question

In: Computer Science

Write a java application that will read a set of values from the user and stores...

Write a java application that will read a set of values from the user and stores them in array a[]. The application should ask the user for the number of values he will enter. You need to do the following methods: 1. Read: This method will read n values from the user and store them in an array a 2. Print: this method will print the array as given in the sample output 3. maxEven: This method will find the maximum value of the even numbers 4. DrawSquarec: this method will draw a square using the elements of the array (see sample) Sample Output How many elements you have:5 Enter the elements: 10 1 4 5 6 The array is: 10 1 4 5 6 The maximum even number is 10 10 10 10 10 10
11111
44444

55555

66666

Solutions

Expert Solution

CODE -

package abc;
import java.util.*;
public class student
{
int[] arr=new int[1000];
void read(int n) //function for reading n values of array's element
{
Scanner sc1=new Scanner(System.in);
System.out.println("Enter the elements-");
int x;
for(int i=0;i<n;i++)
{
x=sc1.nextInt();
arr[i]=x;
}
}
void print(int n) //function for printing array
{
System.out.println("The array is-");
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
void maxeven(int n) //function for finding maximum even number
{
   int num=0;
   for(int i=0;i<n;i++)
   {
       if(arr[i]%2==0)
       {
           if(arr[i]>num)
               num=arr[i];
       }
   }
   System.out.println("The Maximum even number is: "+num);
}
void square(int n) //function for drawing square
{
   System.out.println("Required square is-");
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<n;j++)
       {
           System.out.print(arr[i]);
       }
       System.out.println();
   }
}
public static void main(String args[])
{
student ob=new student();
Scanner sc=new Scanner(System.in);
System.out.println("How many elements you have: ");
int n=sc.nextInt(); //reading value of no of elements
ob.read(n); //calling read function
ob.print(n); //calling print function
ob.maxeven(n); //calling maxeven function
ob.square(n); //calling function for drawing square
}
}

OUTPUT -


Related Solutions

(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
Write a java program that asks user to enter a set of positive integer values. When...
Write a java program that asks user to enter a set of positive integer values. When the user stops (think of sentinel value to stop), the program display the maximum value entered by the user. Your program should recognize if no value is entered without using counter.
in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
JAVA Write a Java console application that prompts the user to enter the radius of a...
JAVA Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Programmer Notes Write and document your program per class coding conventions. Add an instance variable double radius. Generate its get/set methods. Manually type the methods getDiameter(), getCircumference(), and getArea()....
Write a Java program to read a set of integers from a file, dataX, and a...
Write a Java program to read a set of integers from a file, dataX, and a set of ranges from a second file, rangeX, and, for each range [a, b] in rangeX, report the SUM of all the integers in dataX which are in the range [a, b]. As the integers are read from file dataX, insert them in a binary search tree. After all the integers have been inserted into the binary search tree, read the ranges from file...
2. Write a Java program to read a string (a password)from the user and then   check...
2. Write a Java program to read a string (a password)from the user and then   check that the password conforms to the corporate password policy.   The policy is:   1) the password must be at least 8 characters   2) the password must contain at least two upper case letters   3) the password must contain at least one digit   4) the password cannot begin with a digit   Use a for loop to step through the string.   Output “Password OK” if the password...
Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT