تكفون ابي اعرف طريقة حل هالسؤال :
Write a program that inputs an integer, n, from the command line and
displays the string “1 + 2 + 3 + 4 + ... + n = sum.” For example, if the
command-line argument is 7, the output should be:
1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
Make sure the number entered on the command line is positive.
وهذا السؤال ايضا :
كود:
public class RandomLoop
{
public static void main(String [] args)
{
int a, b;
a = (int) (Math.random() * 10 + 1);
System.out.println(“a = “ + a);
do
{
b = (int) (Math.random() * 10 + 1);
System.out.println(“Trying b = “ + b);
}while(a == b);
System.out.println(“a = “ + a + “ and b = “ + b);
}
}
بتغيير randomloop الى do و while loop
وشكرا لكم