1. forஉள்ளிடப்பட்ட வரிகளின் எண்ணிக்கையை கணக்கிட ஒரு வளையத்தைப் பயன்படுத்துதல்

10விசைப்பலகையில் இருந்து வரிகளைப் படிக்கும் மற்றும் எண்களாக இருந்த வரிகளின் எண்ணிக்கையைக் காண்பிக்கும் ஒரு நிரலை எழுதுவோம் . உதாரணமாக:

குறியீடு விளக்கம்
Scanner console = new Scanner(System.in);
int count = 0;
for (int i = 0; i < 10; i++)
{
   if (console.hasNextInt())
      count++;
   console.nextLine();
}
System.out.println(count);
Create a Scanner object to read data from the console.
Store the number of numbers in the count variable.
Loop from 0 to 10 (not including 10).

If a number is entered,
then increase count by one.
Read a line from the console and don't save it anywhere.

Display the calculated count on the screen.
குறிப்பு

வரியில் இடைவெளிகளால் பிரிக்கப்பட்ட பல டோக்கன்கள் இருந்தால், அவற்றில் முதலாவது எண்ணாக இருந்தால், மற்ற டோக்கன்கள் எண்களாக இல்லாவிட்டாலும், hasNextInt()முறை திரும்பும் . trueஅதாவது, ஒவ்வொரு வரியிலும் ஒரு டோக்கன் மட்டுமே உள்ளிடப்பட்டால் மட்டுமே எங்கள் நிரல் சரியாக வேலை செய்யும்.


for2. ஒரு வளையத்தைப் பயன்படுத்தி காரணியைக் கணக்கிடுதல்

எதையும் படிக்காத, மாறாக எதையாவது கணக்கிடும் ஒரு நிரலை எழுதுவோம். ஏதோ கஷ்டம். எடுத்துக்காட்டாக, எண்ணின் காரணியாலானது 10.

ஒரு எண்ணின் காரணியாலானது n(ஆல் குறிக்கப்படும் n!) எண்களின் வரிசையின் பலன்: 1*2*3*4*5*..*n;

குறியீடு விளக்கம்
int f = 1;
for (int i = 1; i <= 10; i++)
   f = f * i;
System.out.println(f);
We store the product of numbers in the f variable.
Loop from 1 to 10 (inclusive).
Multiply f by the next number (save the result in f).
Display the calculated amount on the screen.

தொடக்க மதிப்பு , ஏனெனில் நாம் எண்களால் f = 1பெருக்குகிறோம் . முதலில் இருந்திருந்தால் f, எல்லா எண்களின் பெருக்கமும் பெருக்கப்படும் .f000


3. forதிரையில் வரைவதற்கு லூப்பைப் பயன்படுத்துதல்

திரையில் ஒரு முக்கோணத்தை வரைந்து ஒரு நிரலை எழுதுவோம். முதல் வரியில் 10நட்சத்திரக் குறியீடுகள் உள்ளன, இரண்டாவது - 9நட்சத்திரங்கள், பின்னர் 8போன்றவை.

குறியீடு விளக்கம்
for (int i = 0; i < 10; i++)
{
   int starCount = 10 - i;
   for (int j = 0; j < starCount; j++)
      System.out.print("*");
   System.out.println();
}
Loop through the lines (there should be 10 lines in total).

Calculate how many asterisks should be in the line.
Loop over the individual asterisks
(display starCount asterisks).
Move the cursor to the next line so the lines are separate.

இங்கே நாம் இரண்டு உள்ளமைக்கப்பட்ட சுழல்கள் இருக்க வேண்டும்: கொடுக்கப்பட்ட வரியில் சரியான எண்ணிக்கையிலான நட்சத்திரக் குறியீடுகளைக் காட்டுவதற்கு உள் வளையம் பொறுப்பாகும்.

மேலும் கோடுகள் வழியாக வளைய வெளிப்புற வளையம் தேவைப்படுகிறது.