Question

In: Computer Science

can you assist me in getting the desired output? Homework 5-3 Write a Java program that...

can you assist me in getting the desired output?

Homework 5-3

Write a Java program that prompts the user for an int n. You can assume that 1 ≤ n ≤ 9. You program should use two embedded for loops that produce the following output:

    1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
.
.
.

This is the code:

import java.util.Scanner;

public class PatternOne {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

Scanner scnr = new Scanner(System.in);
  
//Taking rows value from the user

System.out.println("Please enter a number 1...9 ");

int rows = scnr.nextInt();

System.out.println(" ");

for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}

System.out.println();
}  
      
   }
      
}

Solutions

Expert Solution

Sir, Please check the screenshot. The code works perfectly as you want.. please elaborate your issue in comments so that i can help..

You can re-check the code below:

import java.util.Scanner;

public class PatternOne {

        public static void main(String[] args) {

                Scanner scnr = new Scanner(System.in);

                System.out.println("Please enter a number 1...9 ");
                int rows = scnr.nextInt();

                System.out.println(" ");
                for (int i = 1; i <= 9; i++) {
                        for (int j = 1; j <= i; j++) {
                                System.out.print(j + " ");
                        }

                        System.out.println();
                }

        }

}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives •...
Please write the program in JAVA and provide me with the output screenshots!! Assignment Objectives • Be able to write methods • Be able to call methods Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct...
Question 3: getting diagnostics, Write a python program   Write the getting diagnostics function, which reports the...
Question 3: getting diagnostics, Write a python program   Write the getting diagnostics function, which reports the most frequent diagnostic from the patients with the highest symptoms similarity returned by the function similarity to patients. See below for an explanation of exactly what is expected. def getting_diagnostics(patient_set : Set[int], diagnostic_by_patient: Dict[int, str]) -> str: """ Returns a string representing the most frequent diagnostic from the set of diagnostics (stored in the dictionary diagnostic_by_patient) of the patient_set (that is a set of...
Hi can you assist me with this. Can you explain each of the similarities and differences...
Hi can you assist me with this. Can you explain each of the similarities and differences in maybe a short paragraph. Thank you so 3) Provide THREE ways in which Governmental entities are similar to For Profit Entities and THREE ways in which they are different (30 pts )
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
3. Suppose a country's output is above the policy makers' desired level of output and is...
3. Suppose a country's output is above the policy makers' desired level of output and is experiencing a trade deficit. Assume that the policy makers' goals are to achieve the desired level of output (i.e., natural level of output) and balanced trade. Suppose we do not consider the impact of expectations, answer the following questions. (Hint: using the ZZ and NX curves) . a) Is it possible to use fiscal policy to achieve these two goals simultaneously? What kind of...
WRITE A JAVA PROGRAM: For this lab, you will create a 3 x 7 two dimensional...
WRITE A JAVA PROGRAM: For this lab, you will create a 3 x 7 two dimensional array to store how many pounds of food three monkeys eats each day in a week. The 2D array is then passed to functions to find total, average and least amount of food consumption, etc. The program then need to display: the average amount of food the three monkeys ate per day the least amount of food eaten all week by any one monkey....
java program: Input and output the following details. Your program can only receive the correct input....
java program: Input and output the following details. Your program can only receive the correct input. (For example: a notification will be given if you not enter Char data type for Name) Name: Ali bin Ahmad Occupation: Technician Age: 30 Hometown: Negeri Sembilan Years of Service: 12 Gender: Male
Write the following java program: Desc Output the name and time of the runner who came...
Write the following java program: Desc Output the name and time of the runner who came in first, as well as the name and time of the runner who came in last in a marathon race (assuming there are no ties). Input A text file named marathon.txt containing the name and time of each participant in the following format (the file has at least 1 participant, name is just 1 word with no space, and name and time are separated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT