Java 无阵列直方图
我必须写,从用户那里读取三个非负整数,然后 使用符号“*”打印由数字表示的数据的“直方图”,即。, 三个垂直条,底部对齐,高度等于 三个数字。 例如,对于数字3、1和8,结果应如下所示:Java 无阵列直方图,java,histogram,Java,Histogram,我必须写,从用户那里读取三个非负整数,然后 使用符号“*”打印由数字表示的数据的“直方图”,即。, 三个垂直条,底部对齐,高度等于 三个数字。 例如,对于数字3、1和8,结果应如下所示: * * * * * * * * * *** 实际上,我编写了以下程序,但它打印了一个以输入的数字为底的星号金字塔: import java.util.Scanner; public class Task1 { public static void main (String[] args) {
*
*
*
*
*
* *
* *
***
实际上,我编写了以下程序,但它打印了一个以输入的数字为底的星号金字塔:
import java.util.Scanner;
public class Task1 {
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a positive odd number: ");
int n = scan.nextInt();
scan.close();
for (int len=1, sp=n/2; len <= n; len+=2, --sp) {
for (int i = 0; i < sp; ++i)
System.out.print(" ");
for (int i = 0; i < len; ++i)
System.out.print("*");
System.out.println();
}
import java.util.Scanner;
公共课任务1{
公共静态void main(字符串[]args){
扫描仪扫描=新扫描仪(System.in);
System.out.print(“输入正奇数:”);
int n=scan.nextInt();
scan.close();
对于(int len=1,sp=n/2;lenimport java.util.Scanner;
公共班机{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Type in three numbers");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int max = 0;
if (a>b && a>c){
max = a;
} else if (b>a && b>c){
max = b;
} else if (c>a && c>b){
max = c;
}
for (int i = 8; i>=1; --i) {
if (i>a) {
System.out.print(" ");
}else {
System.out.print("*");
}
if (i>b){
System.out.print(" ");
}else {
System.out.print("*");
}
if (i>c){
System.out.print(" ");
}else {
System.out.print("*");
}
System.out.println();
}
}
}从读取三个数字开始!然后尝试使用所有数字。(您需要从最大数字开始倒数)