How can i code this with in java?
All the explanation is in the code comments. Hope this helps!
Code:
import java.util.*;
public class Main
{
public static void main(String[] args) {
// input stream
Scanner sc = new
Scanner(System.in);
// get the input
String input = sc.nextLine();
// split it in numbers
String inputs[] = input.split("
");
// convert it in integers and get
the maximum number
int numbers[] = new
int[inputs.length];
int max = 0;
for(int i=0; i<numbers.length;
i++) {
numbers[i] =
Integer.parseInt(inputs[i]);
// update max
if(numbers[i] > max) {
max = numbers[i];
}
}
// number of rows = max
// number of columns = length of
numbers array
for(int i=1; i<=max; i++)
{
for(int j=0; j<numbers.length;
j++) {
// print # if (i + numbers[j]) >
max
if((i+numbers[j]) > max)
System.out.print(" #");
else
System.out.print(" ");
}
System.out.println();
}
// print the ---- line
for(int j=0; j<numbers.length;
j++)
System.out.print("--");
System.out.println();
// print the numbers
for(int j=0; j<numbers.length;
j++)
// for double digit
if(numbers[j] >= 10)
System.out.print(numbers[j]);
else
System.out.print(" " +
numbers[j]);
System.out.println();
}
}
Sample run:
Code screenshots:
Need help coding with Java. Explanation in code would be
greatly appreciated. Thanks
Bar graph 2.0 Write a program that accepts a list of up to 100 integers and displays a bar graph showing the frequencies of the values and the corresponding percentage frequency distributions (printed to 1 significant digit). Example runs are shown below. Number of values to graph: Enter the integer values separated by a space: Bar graph for 3 #1111# 01110 100.01 umber of integers to readi...
For JAVA Please post code in bold. Thank you.
Print numbers 0, 1, 2, ..., userNum as shown, with each number
indented by that number of spaces. For each printed line, print the
leading spaces, then the number, and then a newline. Hint: Use i
and j as loop variables (initialize i and j explicitly). Note:
Avoid any other spaces like spaces after the printed number. Ex:
userNum = 3 prints:
0
1
2
3
Challenge 4.6.1: Nested loops ndent...
How would I code this method in Java using a scanner? Begin by asking how many spaces the row should be with a prompt using System.out.print like the following, with 40 as the maximally allowed number of spaces: (user input shown bold) Please enter the number of spaces for the game (1-40): eight To do this, use the promptNumberReadLine method that you will write, described on the back page. If the user does not type a number in the correct...
In java, how can I convert this text file format: n=6 m=7 1 2 5 4 9 5 6 2 3 2 3 4 3 5 6 2 6 4 2 // end of file into this text file format: 1,2,5 1,4,9 1,5,3 2,3,2 3,4,3 5,6,2 6,4,2 This is how to read the first text file: The first line of each file below contains the number of vertices and the number of edges in the graph (in the format "n=XXXX...
I have C++ code. How I can change to Java code #include <iostream> using namespace std; int initialNumber[4]; int main() { void ShowResult(); //initialization int NuberOfpage[20]={1,0,7,1,0,2,1,2,3,0,3,2,4,0,3,0,2,1,0,7},i,j,f12[3]; int num1=0,num2=0,countr=0,framsize=3; int inital,current,current1; for(i=0;i<3;i++) { initialNumber[i]=-1; } for(j=0;j<20;j++) { num1=0,num2=0; for(i=0;i<3;i++) { if(initialNumber[i]==NuberOfpage[j]) { num1=1; num2=1; break; } } if(num1==0) { for(i=0;i<3;i++) { if(initialNumber[i]==-1) { initialNumber[i]=NuberOfpage[j]; num2=1; break; } } } if(num2==0) ...
This is a java code but I need to understand the logic of how is going to run. Can someone help please. int i = 1; while (i <= 5) { xMethod(i); i++; } System.out.println("i is " + i); } public static void xMethod(int i) { do { if (i % 2 != 0) System.out.print(i + " "); i--; } while (i >= 1); System.out.println();
Please write in Java in Jgrasp check code before posting Please
write in Java in Jgrasp check code before posting
Please write in Java in Jgrasp check code before posting, will
give thumbs up
FOP- 2. Write a program that ciphers a plain text message using double transposition scheme and vice versa. [50 Marks) The program should accept five tuples of input: plain text, row, column, permutation of row and columns. An example of encrypted text for the plain text...
What this Assignment Is About: Review on Java I topics, such as primitive data types, basic I/O, conditional and logical expressions, etc. Review on Java loops. Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are...
please show the code in java,thanks
5. Perfect Numbers Version 2: Write a program which computes perfect numbers according the following algorithm: for each prime, p: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 if 2P 1 s prime (2P (2 is perfect: print both p and (2P 1)(2) Note: You will need to use the Biglnteger clas for thist
In Java code, for a topological sort assignment: How I load a .txt file and use its information to populate a hashtable that maps IDs to characters, and add the IDs as nodes in the graph.