in java i need to solve this question. Preferably without any advanced java tech
ID: 3776541 • Letter: I
Question
in java i need to solve this question. Preferably without any advanced java techniques, this is for an intro programming course.
Problem 1
Write a program to accomplish the following tasks:
1) make a random number between 10 and 20;
2) make an array of the size of the random number;
3) fill the array with random integers from 0 to 999;
4) print lines of output for each of these:
a) the original members of the array
b) every element at an even index based on the original displayed array
c) every even element based on the original displayed array
d) the reverse of the original array
e) the first and last element based on the original displayed array, use the length not a literal number
f) swap the first and last element based on the original displayed array
g) shift all elements to the right once, move the last element to the first based on the original displayed array
h) replace all even elements with the number zero based on the original array
i) replace each element except the first and last with the larger of its two neighbors based on the original displayed array
j) remove the two middle elements based on the original displayed array
k) move all odd elements to the front otherwise preserving the order of the array based on the original displayed array
l) display true if the original array is stored in increasing order
m) display true if the array contains two adjacent elements that are equal
n) compute the alternating sum of all elements in the array, for example: 1 2 3 4 5 would be computed as 1 - 2 + 3 - 4 + 5 ...
o) display a bar chart equal to the value of the number in each element, for example: 1 2 3 4 5 would display as:
*
**
***
****
*****
Problem 2
Take problem 1.o (the last problem directly above) and make it work for negative numbers.
If the numbers were 1, -3, 4, -5, 6
_____* ç the underscores represent spaces, if -5 were the biggest number, you know how far
__* before zero to start
_____****
*****
_____******
Explanation / Answer
1.
import java.io.*;
import java.util.*;
public class Randomnumbers
{
public static void main(String args[])
{
rArray = new double[];
Rnumbers rnum = new Rnumberes();
for (int i = 10;i < 20; i++)
{
rArray[i] = rand.nextInt();
int size = rArray.length;
}
printArray();
int j,temp;
j= i - 1;
i = 0;
while (i<j)
{
temp rArray[i];
rArray[i] = rArray[j];
rArray[j] = temp;
i++;
j--;
}
System.out.print("now the reverse of Array is : ");
for( i=0; i<size; i++)
{
System.out.print(rArray[i] + " ");
}
}
private static void PrintArray()
{
System.out.println("Random numbers:-");
for( int i = 0; i<1000; i++)
{
System.out.pritnln(rArray[i]);
}
}
1.4.O
class sample
{
public static void main (String args[])
{
for(int i = 1; i<6 ; i++)
{
for (int j=1; j<i; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
2.
public class Rnumbers
{
public static void main(String args[])
{
int[] num = {1, -3, 4, -5, 6};
for (int i=0; i< num.length; i++)
{
int x = num[i];
if(x>0)
{
for ( int j=0;j<5; j++)
System.out.print(" ");
for(int k=0; k<x; k++)
System.out.println("*");
}
else
{
for(int j=0; j<(5+x); j++)
System.out.print(" ");
for( k=0; k<x; k++)
System.out.print("*");
}
}
}}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.