Write a program to input 10 numbers and output the sum of the two largest values in the sequence.
Sample Output:
Enter the Numbers >> 10 2 3 4 5 6 7 9 9 10
Sum >> 20
Try Again Y/N?
Jaya Jusco (JJ) Sdn Bhd needs you to develop an application to calculate their customer JJ point’s reward. Define a class named Customer with the following variables declarations:
String CustName;
String CustAddress;
int pointRewards;
Create a java program which allows the user to enter two values (Using JOptionPane) to be divided. The program catches an exception if either of the entered values is not an integer.
Declare three integers—two to be input by the user and a third to hold the result after dividing the first two. The numerator and denominator variables must be assigned starting values because their values will be entered within a try block. Also declare an input String to hold the return value of the JOptionPane showInputDialog() method.int numerator = 0, denominator = 0, result; String display;
Add a try block that prompts the user for two values, converts each entered String to an integer, and divides the values, producing result(Cast the result to a double).
Add a catch block that catches an Arithmetic Exception object if division by 0 is attempted. If this block executes, display an error message, and force result to 0.
Create a class named Invoice containing fields for an item number, name, quantity, price, and total cost. Create a constructor to pass the value of the item name, quantity, and price. Also include displayLine() method that calculates the total cost for the item (As price times quantity) then displays the item number, name, quantity price, and total cost. Save the class as Invoice.java.
by CodeChum Admin
Manipulating values from a series of numbers is fun, but let's try exploring the use of loops a little more.
How about printing out each digit of a number starting from its rightmost digit, going to its leftmost digit?
Instructions:
Input
A line containing an integer.
214Output
Multiple lines containing an integer.
4
1
2Instructions:
Instructions
Input
A line containing an integer.
10Output
Multiple lines containing an integer.
9
7
5
3
1Create a program using a console application name "DragonKiller". The program should ask the user to enter his/her name and surname. Create a method name RemoveSpace() to remove space between the name and the surname entered by the user. Count the number of characters within the newly created string (nameSurname). The total number of characters (Name and Surname) should be used as the size of your arrayDragon (type integer). Populate your arrayDragon with a series of odd random numbers between 10 and 50. Display all arrayDragon elements and their corresponding indexes before executing. The insertionSort method allows the user to enter a value from the arrayDragon element to search for and be removed (Killed). • Loop through the array until you find the value (Use the binarySearch to locate the value with in your array) and kill that value from the arrayDragon. By replacing the value findDragon with a Zero (0) • Print out arrayDragon with the killed element.
Write a program that declares and initializes an array of 7 integers. The program uses these static methods to perform different operations on the array:
void printArray(int[] arr) – takes the array as parameter and prints the array in horizontal order
int sumOfArray(int[] arr) – takes the array as parameter and returns the sum of the array
int getHighest(int[] arr) – takes the array as parameter and returns the highest value in the array
int resetArray(int[] arr) – takes the array as parameter and resets the value of each element to 0
Sample output:
Here’s the array:
3 1 3 2 1 9 1
Sum: 20
Highest: 9
Here’s the array:
0 0 0 0 0 0 0
Create a static method
public static int pow(int base, int exp)
that returns the power value of base raised to its exponent. Use this method in a program that first asks for a base value and an exponent value, calls pow() and then prints the result.
Sample output:
Enter the base: 2
Enter the exponent: 3
The power value is 8
Write a program that uses a static method called printMessage that takes a string and an integer as parameters. The string and integer parameters represent a person’s name and age. When printMessage is called with arguments “Joan” and 18, the method prints “Joan, you are 18 years old”.
Sample output:
Enter your name: Joan
Enter your age: 18
Joan, you are 18 years old