فيما يلي امثلة على الحلقات while باستخدام جافا

while loops

 برنامج جافا يطبع كلمة hello world ل 100 مرة

//write java program to print the numbers from 1 to 100   --  use while loop
  
int i=1;
while(i<=100)
{
 System.out.println("hello world");
 i++;
}

 

 

برنامج جافا يطبع الاعداد من 1 الى 100

//write java program to print the numbers from 1 to 100   --  use while loop
  
int i=1;
while(i<=100)
{
 System.out.println(i);
 i++;
}

 

اكتب برنامج بلغة جافا java يقوم بطباعة الاعداد الفردية بين 0 و 100

//using while loops: write java program to print all odd numbers between 0 to 100
  
int t=0;
while(t<=100) {
 if(t%2==1)
 System.out.println(t);
 t++;
}

 

اكتب برنامج بلغة جافا java يطبع الاعداد الزوجية بين 0 و 100

//write java program to print all even numbers between 0 to 100

int t=0;
while(t<=100) {
 if(t%2==0)
         System.out.println(t);
 t++; 
}

 

 

باستخدام الحلقات والمصفوفات:

اكتب برنامج بلغة جافا java يطلب من المستخدم ادخال اسماء وعلامات الطلاب, ويقوم بحساب مجموع العلامات ومتوسط العلامات واعلى علامة مع اسم الطالب الحاصل عليها, واقل علامة مع اسم الطالب الحاصل عليها, 

ملاحظة: البرنامج يجب ان يطبع في النهاية تقرير عبارة عن جدول يحوي معلومات الطلبة(الاسم, العلامة) ويطبع متوسط العلامات ومجموع العلامات واعلى علامة واقل علامة.

import java.util.Scanner;

class Main {
  public static void main(String[] args) {

//using while loop, write java program to ask user to enter students names, and students marks,
//and calculate total marks and average of marks, and highest mark with it's student name, and lowest mark with it's student name.
//program should print a report contains a table having the students info: name, mark,
//and finally prints the average and total marks and lowest and highest marks.
  
Scanner input=new Scanner(System.in);
System.out.println("enter number of students");
int students_num=input.nextInt();
String []names=new String[students_num];
int []marks=new int[students_num];
  
int total_marks=0, highest_mark_index=0 ,lowest_mark_index=0;
int i=0;
int temp_mark;
while(i10 || temp_mark<0)
  System.out.println("invalid entry");
  else
  {
  marks[i]=temp_mark;
  flag=false;
  }
      
  }
  
  
  
  total_marks=total_marks+marks[i];
  if(marks[i]>marks[highest_mark_index])
  highest_mark_index=i;

  if(marks[i]

 

 

 

ابحث عن مسائل برمجة جافا | Java programming بالانجليزي

هل أعجبك المحتوى؟

محتاج مساعدة؟ تواصل مع مدرس اونلاين الان!

التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول