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


for3. స్క్రీన్‌పై గీయడానికి లూప్‌ని ఉపయోగించడం

స్క్రీన్‌పై త్రిభుజాన్ని గీసే ప్రోగ్రామ్‌ను వ్రాద్దాం. మొదటి పంక్తిలో 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.

మేము ఇక్కడ రెండు సమూహ లూప్‌లను కలిగి ఉండాలి: ఇచ్చిన లైన్‌లో సరైన సంఖ్యలో ఆస్టరిస్క్‌లను ప్రదర్శించడానికి అంతర్గత లూప్ బాధ్యత వహిస్తుంది.

మరియు పంక్తుల ద్వారా లూప్ చేయడానికి బాహ్య లూప్ అవసరం.