Accept 5 numbers in an array and display it.
printf("1 3 5 7 9\n");
import java.util.Arrays; import java.util.Scanner; public class Answers { public static void main(String[] args) { //Creates a scanner object named console. Scanner console = new Scanner(System.in); //Variabels int [] numbers = new int [10]; double avg = 0.0; double median = 0.0; int max = numbers[0]; double count = 0.0; //User input. for (int i = 0; i < numbers.length; i++){ System.out.print("Number: "); numbers[i] = console.nextInt(); } //break System.out.println("==============="); //finds the average and max value. for (int i = 0; i < numbers.length; i++){ count += numbers[i]; avg = count / numbers.length; //average if (numbers[i] > max){ //finds the max value. max = numbers[i]; } } median = (numbers[4] + numbers[5])/2; //Median value //Display to user. System.out.println("Highest value found: " + max); //Show maximum value found in array System.out.printf("Median is: %.3f \n",median); //Show median System.out.printf("Average is: %.3f \n",avg); //Show average sortAsc(numbers); //Print out whole array ascending } //Method for sorting an Array ascending. public static void sortAsc(int [] array){ for (int i = 0; i < array.length; i++){ Arrays.sort(array); System.out.println(array[i]); } } } This should do everything you asked for, hope this helps!
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }
An array stores several values - for example, several numbers - using a single variable name. The programmer can access the individual values with a subscript, for example, myArray[0], myArray[5]. The subscript can also be a variable, for example, myArray[i], making it easy to write a loop that processes all the elements of an array, or some of them, one after another.
which element of the array does this expression reference num[5]
5
An array consisting of 5 rows and 5 columns of numbers (or variables).
Create an array like so $numbers = array(); $numbers['0'] = "ZERO"; $numbers['1'] = "ONE"; and so on.. till you decide that's enough then to print it, echo the array with the desired key like so.. Example I print 5 in words echo $numbers['5']; which would print FIVE Good luck
Heres something i whipped up in a hurry... This uses the Bubble Sort method found (related links) #include <iostream> using namespace std; int main(int argc, const char* argv) { int arraysize = 5; //Unsorted array size int array [] = { 5, 3, 4, 2, 1 }; //The array of numbers itself //Display the unsorted array cout << "Before: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; //Acctually sort the array int tmp=0; //Used for swaping values for (int loop=0; loop <= (arraysize - 1); loop++) { for (int c=0; c <= (arraysize - 1); c++) //The sort loop { if (array[c] > array[c + 1]) { //Swaps the two values in the array tmp = array[c]; array[c] = array[c + 1]; array[c + 1] = tmp; //Cleanup tmp = 0; } } } //Display the sorted array cout << "After: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; return 0; }
You don't need an array for that. Just do the multiplication, for example: result = factor1 * factor2; Or: result = 5 * 8;
printf("1 3 5 7 9\n");
It can be done with 7 LED segments. More LEDs will be needed if a regular rectangular array is required, but many of these will never light and could be omitted to save money but then it would not be regular. The smallest standard regular rectangular array sold is 5 by 7 or 35 total LEDs, but this will display all alphanumeric characters and even then some LEDs will be unused unless other things are displayed too. Just guessing the smallest regular array is probably 3 by 5 or 15 total LEDs, but at most 13 of these LEDs would be used by the digits the other 2 LEDs could be omitted to save money. Such an array could be wired to be driven as a 7 segment display using a few ordinary diodes to light the 6 shared LEDs as part of multiple "segments".
import java.util.Arrays; import java.util.Scanner; public class Answers { public static void main(String[] args) { //Creates a scanner object named console. Scanner console = new Scanner(System.in); //Variabels int [] numbers = new int [10]; double avg = 0.0; double median = 0.0; int max = numbers[0]; double count = 0.0; //User input. for (int i = 0; i < numbers.length; i++){ System.out.print("Number: "); numbers[i] = console.nextInt(); } //break System.out.println("==============="); //finds the average and max value. for (int i = 0; i < numbers.length; i++){ count += numbers[i]; avg = count / numbers.length; //average if (numbers[i] > max){ //finds the max value. max = numbers[i]; } } median = (numbers[4] + numbers[5])/2; //Median value //Display to user. System.out.println("Highest value found: " + max); //Show maximum value found in array System.out.printf("Median is: %.3f \n",median); //Show median System.out.printf("Average is: %.3f \n",avg); //Show average sortAsc(numbers); //Print out whole array ascending } //Method for sorting an Array ascending. public static void sortAsc(int [] array){ for (int i = 0; i < array.length; i++){ Arrays.sort(array); System.out.println(array[i]); } } } This should do everything you asked for, hope this helps!
A lot more,.....45,1. 5,9. 15,3. So basically 3 dude
The variable, X, has to undergo the following: X*9÷5+32 [The reverse would be to accept a Fahrenheit temperature: (F-32)*5÷9]
Accept a number. Display all numbers from 0 up to it. Example: If input number is 5, output should be 0 1 2 3 4Accept two numbers. Display all numbers between them. Example: If input numbers are 10 and 15, output should be 11 12 13 14Accept a number. Display all even numbers less than that number. Example: If input number is 7, output should be 2 4 6Accept a number and display its multiplication table. Example: If input number is 3, output should be 3 X 1 = 3, 3 X 2 = 6..... [For/while loop needed]Accept a number and find the sum of all numbers from 0 till that number. If input number is 3, output should be 6 (0 + 1 + 2 + 3)Create two int variables a and b, each = 30000. Try to assign c = a +b. Display c. Answer is not 60000. Why?Good luck.
int array[10] = {...}; for (int i = 0; i < 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }