I am a new learner of Java.

Thq question is "Write a Java program ShowStars.java so that java ShowStars numA1 numB1 .... display a sequence of stars "*", starting from position numA1 and ending at position numB1. If there are further such integer pairs, say, numA2 and numB2, do the same for the next line. For example,
java ShowStars 2 3 1 4
gives

**
****


my incomplete code is shown below:

import java.util.Scanner;
import java.lang.String;

public class ShowStars {
public static void main(String[] args) {
    String aString;
    
    for (int i = 0; i < num1.length; i++){
        for (int j = 0; j < num2.length; j++)
            System.out.print("*");
    }
}

Any suggestions what should I add?

Ignore my incomplete code above.

Here is my code but it is still not finished.

import java.util.Scanner;

public class Stars {
    public static void main(String args[]) {
        System.out.println("Enter an int:");

        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        int num3 = sc.nextInt();
        int num4 = sc.nextInt();

        for(int i = 0; i < num1; i++)
            System.out.print("*");
            for(int j = 0; j < num2; j++)
                System.out.print(" ");

        System.out.println();
    }
}

For example,
java ShowStars 2 3 1 4

First comment about your code is that it doesn't follow the example you show.
The String[] args passed to the main() method would contain the args shown by your command line:
args[0] is 2, args[1] is 3 etc

it is still not finished.

Do you have any specific problems? If so, ask some questions about them.

import java.util.Scanner;
import java.lang.String;

class Stars {
    public static void main(String[] args) {
        try {
            Scanner input = new Scanner(System.in);
            System.out.println("enter the number: ");
			String aString;
			aString = input.nextLine();
			int aInt = Integer.parseInt(aString);
            for(int i = 0; i < aString; i++){
                for(int j = 0; j < aString; j++) {
                    System.out.print("*");
                }
            System.out.print(""); }
        }
    catch(Exception e){}
}
}

You need to post what errors do you get. Don't expect that is easy for us to take your code and run it. Or that we read it line by line and expect to understand what you were thinking.

Also I happened to run the latest code and this is wrong: int i = 0; i < aString; i++ aString is a String. What is it doing there? You are suppose to put a boolean expression there in order to tell when the loop will stop.

This article has been dead for over six months. Start a new discussion instead.