Home / Expert Answers / Computer Science / 1-write-a-program-to-draw-a-right-justified-triangle-given-the-height-as-input-the-first-row-has-o-pa205

(Solved): 1- Write a program to draw a right-justified triangle given the height as input. The first row has o ...



1- Write a program to draw a right-justified triangle given the height as input. The first row has one asterisk (*) and increases by one for each row. Each asterisk is followed by a blank space and each row ends with a newline.

Ex: If the input is:

3

the output is:

    * 
  * *
* * * 

import java.util.Scanner;

public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

/* Type your code here. */
int height = scnr.nextInt();

// draw right-justified triangle
for (int i = 1; i <= height; i++) {
for(int j=1;j<=i; j++){
// print each asterisk is followed by a blank space
System.out.print("* ");
}

// to ends witha newline
System.out.println();
}

}
}
1:Compare output \( \boldsymbol{\wedge} \)
\( 0 / 3 \)
Output is nearly correct, but whitespace differs. See highlights below

2-(1) Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lower even number. Hint: Use an if statement and the % operator to detect if n is odd, decrementing n if so.

Enter an integer:
7
Sequence: 6 4 2 0

(2) If n is negative, output 0. Hint: Use an if statement to check if n is negative. If so, just set n = 0.

Enter an integer:
-1
Sequence: 0

Note: For simplicity add a space after each output value, including the last value.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int n;
int i;

System.out.println("Enter an integer:");
n = scnr.nextInt();

System.out.print("Sequence:");
/* Type your code here. */

Please answer these questions and I will give you a Thumbs up

1:Compare output Output is nearly correct, but whitespace differs. See highlights below. Input Your output Expected output 2:Compare output 2 / 2 Input Your output 3:Compare output Output is nearly correct, but whitespace differs. See highlights below. Input Your output Expected output 4:Compare output Output is nearly correct, but whitespace differs. See highlights below. Input Expected output


We have an Answer from Expert

View Expert Answer

Expert Answer


This question contains 2 parts.In this step i will explain the frist part sol.Frist i explain which steps have been taking to solve this pattern quest
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe