JAVA OOP
181 subscribers
13 photos
2 videos
1 file
9 links
شرح + حل واجبات جميع الاقسام + امثله لاتنتهي + كوزرات
للتواصل او للارسال سؤالك @sz6ss_bot
المسؤول عن القناه @sz6ss
Download Telegram
JAVA OOP
واجبات#الانظمه مسائي
Q3//
public class main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
JAVA OOP
واجبات#الانظمه مسائي
Q4//

import java.util.Scanner;


public class main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter positive numbers (enter a non-positive to stop):");

while (true) {
int number = input.nextInt();
if (number <= 0) {
System.out.println("Terminated.");
break;
}
}
}
}
JAVA OOP
واجبات#الانظمه مسائي
Q7
public class main {
public static void main(String[] args) {
int term = 1;
for (int i = 0; i < 10; i++) {
System.out.print(term + " ");
term = term * 2 + 1;
}
}
}
سؤال المختبر القادم للهياكل /علوم صباحي
//
اكتب برنامج يقرء مصفوفه احاديه مصفوفة ثنائيه ثم يطلب من المستخدم اختيار نوع المصفوفه ووحجم المصفوفه وعناصر المجموعه ثم طباعتها واجراء 5 عمليات عليها ويبقى يطلب من المستخدم اجراء عمليات لحين طلب المستخدم الخروج من العمليات
مًحًمًدٍ
سؤال المختبر القادم للهياكل /علوم صباحي // اكتب برنامج يقرء مصفوفه احاديه مصفوفة ثنائيه ثم يطلب من المستخدم اختيار نوع المصفوفه ووحجم المصفوفه وعناصر المجموعه ثم طباعتها واجراء 5 عمليات عليها ويبقى يطلب من المستخدم اجراء عمليات لحين طلب المستخدم الخروج…
import java.util.Scanner;
public class hmd {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean exit = false;

while (!exit) {
System.out.println("اختر نوع المصفوفة: 1. أحادية 2. ثنائية 3. ثلاثية 4. خروج");
int choice = scanner.nextInt();

switch (choice) {
case 1:
// مصفوفة أحادية
System.out.println("أدخل عدد العناصر في المصفوفة الأحادية:");
int size = scanner.nextInt();
int[] array = new int[size];
System.out.println("أدخل العناصر:");
for (int i = 0; i < size; i++) {
array[i] = scanner.nextInt();
}
printArray(array); // طباعة المصفوفة
arrayD1(array);
break;

case 2:
// مصفوفة ثنائية
System.out.println("أدخل عدد الصفوف:");
int rows = scanner.nextInt();
System.out.println("أدخل عدد الأعمدة:");
int cols = scanner.nextInt();
int[][] matrix = new int[rows][cols];
System.out.println("أدخل العناصر:");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix[i][j] = scanner.nextInt();
}
}
printArray(matrix); // طباعة المصفوفة
arrayD2(matrix);
break;

case 3:
// مصفوفة ثلاثية
System.out.println("أدخل عدد الطبقات:");
int layers = scanner.nextInt();
System.out.println("أدخل عدد الصفوف:");
int threesRows = scanner.nextInt();
System.out.println("أدخل عدد الأعمدة:");
int threesCols = scanner.nextInt();
int[][][] threeDMatrix = new int[layers][threesRows][threesCols];
System.out.println("أدخل العناصر:");
for (int i = 0; i < layers; i++) {
for (int j = 0; j < threesRows; j++) {
for (int k = 0; k < threesCols; k++) {
threeDMatrix[i][j][k] = scanner.nextInt();
}
}
}

break;

case 4:
exit = true;
System.out.println("تم الخروج من البرنامج.");
break;

default:
System.out.println("اختيار غير صالح.");
}
}

scanner.close();
}

// عمليات على المصفوفة الأحادية
private static void arrayD1 (int[] array) {
boolean backToMenu = false;

while (!backToMenu) {
printArray( array);
System.out.println("اختر عملية:");
System.out.println("1. حساب مجموع العناصر");
System.out.println("2. حساب متوسط العناصر");
System.out.println("3. العثور على أكبر عنصر");
System.out.println("4. العثور على أصغر عنصر");
System.out.println("5. عكس المصفوفة");
System.out.println("6. العودة إلى القائمة الرئيسية");

java
👍2
int operation = new Scanner(System.in).nextInt();
switch (operation) {
case 1:
System.out.println("مجموع العناصر: " + sum(array));
break;
case 2:
System.out.println("متوسط العناصر: " + average(array));
break;
case 3:
System.out.println("أكبر عنصر: " + max(array));
break;
case 4:
System.out.println("أصغر عنصر: " + min(array));
break;
case 5:
reverseArray(array);
break;
case 6:
backToMenu = true;
break;
default:
System.out.println("اختيار غير صالح! يرجى إدخال رقم من 1 إلى 6.");
}
}
}

// عمليات على المصفوفة الثنائية
private static void arrayD2(int[][] matrix) {
boolean backToMenu = false;

while (!backToMenu) {
printArray(matrix);
System.out.println("اختر عملية:");
System.out.println("1. حساب مجموع العناصر");
System.out.println("2. حساب متوسط العناصر");
System.out.println("3. العثور على أكبر عنصر");
System.out.println("4. العثور على أصغر عنصر");
System.out.println("5. عكس المصفوفة");
System.out.println("6. العودة إلى القائمة الرئيسية");

int operation = new Scanner(System.in).nextInt();
switch (operation) {
case 1:
System.out.println("مجموع العناصر: " + sum(matrix));
break;
case 2:
System.out.println("متوسط العناصر: " + average(matrix));
break;
case 3:
System.out.println("أكبر عنصر: " + max(matrix));
break;
case 4:
System.out.println("أصغر عنصر: " + min(matrix));
break;
case 5:
reverseMatrix(matrix);
break;
case 6:
backToMenu = true;
break;
default:
System.out.println("اختيار غير صالح! يرجى إدخال رقم من 1 إلى 6.");
}
}
}


// دالة لعكس المصفوفة الأحادية
private static void reverseArray(int[] array) {
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
System.out.println("المصفوفة بعد العكس:");
printArray(array);
}

// دالة لعكس المصفوفة الثنائية
private static void reverseMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
reverseArray(matrix[i]);
}
System.out.println("المصفوفة الثنائية بعد العكس:");
printArray(matrix);
}



private static int sum(int[] array) {
int total = 0;
for (int i = 0; i < array.length; i++) {
total += array[i];
}
return total;
}

private static double average(int[] array) {
return (double) sum(array) / array.length;
}

private static int max(int[] array) {
int max = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}

private static int min(int[] array) {
int min = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}

private static int sum(int[][] matrix) {
int total = 0;
for (int i = 0; i < matrix.length; i++) {
total += sum(matrix[i]); // استخدام دالة sum للمصفوفة الأحادية
}
return total;
}
private static double average(int[][] matrix) {
return (double) sum(matrix) / (matrix.length * matrix[0].length);
}

private static int max(int[][] matrix) {
int max = matrix[0][0];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
}
return max;
}

private static int min(int[][] matrix) {
int min = matrix[0][0];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] < min) {
min = matrix[i][j];
}
}
}
return min;
}



private static void printArray(int[] array) {
System.out.println("عناصر المصفوفة الأحادية:");
for (int i : array) {
System.out.print(i + " ");
}
System.out.println();
}

private static void printArray(int[][] matrix) {
System.out.println("عناصر المصفوفة الثنائية:");
for (int[] row : matrix) {
for (int j : row) {
System.out.print(j + " ");
}
System.out.println();
}
}


}
اكتب برنامج بلغه جافا يقرء مدخلين من المستخدم واستخدم الدوال لحساب المجموع وطباعته
الكود الاخذناه بالعملي
import java.util.Scanner;

public class App {

public static Scanner read=new Scanner(System.in);
public static void main(String[] args) {

System.out.println("enter a&b:");
int a= read.nextInt();
int b=read.nextInt();
int c=multi(a,b);
output(c);
read.close();
}
public static int multi (int a,int b) {





int multi =a*b;
return multi;
}
public static void output (int c) {
System.out.println("the multi: "+c);

}
}



#مختبر علوم الحاسوب
واجبات#انظمه_صباحي
JAVA OOP
واجبات#انظمه_صباحي
باجر انزل الحلول اذا احد حاب يقوي نفسه خل يحاول يحلهن
👍2
JAVA OOP
واجبات#انظمه_صباحي
Q1
import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter N : ");
int N = scanner.nextInt();
int largest = 0;

for (int i = 0; i < N; i++) {
System.out.print("Enter num" + (i + 1) + ": ");
int num = scanner.nextInt();
if (num > largest) {
largest = num;
}
}
System.out.println("Largest number: " + largest);

}
}

Q2

import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of integers (N): ");
int N = scanner.nextInt();

for (int i = 0; i < N; i++) {
System.out.print("Enter number " + (i + 1) + "= ");
int num = scanner.nextInt();
if (num > 0) {
System.out.println(num + " is positive.");
} else if (num < 0) {
System.out.println(num + " is negative.");
} else {
System.out.println(num + " is zero.");
}
}
}
}

Q3
java
import java.util.Scanner;

public class hh {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of characters (N): ");
int N = scanner.nextInt();

for (int i = 0; i < N; i++) {
System.out.print("Enter character " + (i + 1) + ": ");
char ch = scanner.next().charAt(0);
if (Character.isLetter(ch)) {
System.out.println(ch + " is an alphabet.");
} else {
System.out.println(ch + " is not an alphabet.");
}
}

}
}

#
Q4
import java.util.Scanner;

public class hh {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of characters (N): ");
int N = scanner.nextInt();

for (int i = 0; i < N; i++) {
System.out.print("Enter character " + (i + 1) + ": ");
char ch = scanner.next().charAt(0);
if ("AEIOUaeiou".indexOf(ch) != -1) {
System.out.println(ch + " is a vowel.");
} else if (Character.isLetter(ch)) {
System.out.println(ch + " is a consonant.");
} else {
System.out.println(ch + " is not an alphabet.");
}
}

}
}
👍1
JAVA OOP
باجر انزل الحلول اذا احد حاب يقوي نفسه خل يحاول يحلهن
Q5
import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first integer: ");
int firstNum = scanner.nextInt();
System.out.print("Enter second integer: ");
int secondNum = scanner.nextInt();
System.out.print("Enter operation (+, -, *, /): ");
char operation = scanner.next().charAt(0);

switch (operation) {
case '+':
System.out.println("Result: " + (firstNum + secondNum));
break;
case '-':
System.out.println("Result: " + (firstNum - secondNum));
break;
case '*':
System.out.println("Result: " + (firstNum * secondNum));
break;
case '/':
if (secondNum != 0) {
System.out.println("Result: " + (firstNum / (double) secondNum));
} else {
System.out.println("Cannot divide by zero.");
}
break;
default:
System.out.println("Invalid operation.");
}
scanner.close();
}
}

Q6

import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter month number (1-12): ");
int month = scanner.nextInt();
int days;

switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
days = 31;
break;
case 4: case 6: case 9: case 11:
days = 30;
break;
case 2:
days = 28;
break;
default:
days = 0;
}

if (days != 0) {
System.out.println("Days in month: " + days);
} else {
System.out.println("Invalid month number.");
}

}
}
JAVA OOP
واجبات#انظمه_صباحي
import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of elements: ");
int N = scanner.nextInt();
int[] numbers = new int[N];

System.out.println("Enter " + N + " numbers:");
for (int i = 0; i < N; i++) {
numbers[i] = scanner.nextInt();
}

System.out.print("Enter specific number to count: ");
int specificNum = scanner.nextInt();
int count = 0;

for (int number : numbers) {
if (number == specificNum) {
count++;
}
}
System.out.println(specificNum + " appears " + count + " times.");

}
}

Q10
import java.util.Scanner;

public class hh {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a maximum odd number (n): ");
int nValue = scanner.nextInt();

if (nValue % 2 == 1) {
int sumOdd = 0;
int oddCount = 0;

System.out.print("Odd numbers between 1 and " + nValue + ": ");
for (int i = 1; i <= nValue; i += 2) {
System.out.print(i + " ");
sumOdd += i;
oddCount++;
}
double average = oddCount > 0 ? (double) sumOdd / oddCount : 0;
System.out.println("\nAverage of odd numbers: " + average);
} else {
System.out.println("Please enter an odd number.");
}

}
}
JAVA OOP
واجبات#انظمه_صباحي
Q11
import java.util.Scanner;

public class hh {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);


System.out.print("Enter N: ");
int N = read.nextInt();
System.out.print("Enter M: ");
int M = read.nextInt();


System.out.println("Even numbers between " + N + " and " + M + ":");
for (int i = N; i <= M; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
}
}

Q13

import java.util.Scanner;

public class hh {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);

System.out.print("Enter student's average: ");
double average = read.nextDouble();


if (average > 90) {
System.out.println("The student is eligible.");
} else {
System.out.println("The student is not eligible.");
}
}
}
JAVA OOP
واجبات#انظمه_صباحي
Q16
import java.util.Scanner;
public class hh {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter N: ");
int N = scanner.nextInt();

System.out.println("Figure:");
for (int i = N; i > 0; i -= 4) {
for (int j = i; j > i - 4 && j > 0; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}

**بقن كم سؤال مافهمتهن
اسماء الرموز في البرمجه بصوره عامه
👏3👍1
2_3_4_5_merged.pdf
913.2 KB
نحاول نحل هذا الملف اغلب الاقسام معتمده عليه
JAVA OOP pinned a file
JAVA OOP
2_3_4_5_merged.pdf
#السلايد الاول
👍1
JAVA OOP
#السلايد الاول
السؤال 1. إعادة كتابة جمل if باستخدام مشغل الشرط (Conditional Operator):

a.
سؤال:
if (count % 10 == 0)
System.out.print(count + "\n");
else
System.out.print(count + " ");


شرح:
هنا تقوم الجملة بفحص ما إذا كان العدد count يقبل القسمة على 10. إذا كان الأمر كذلك، يتم طباعة count مع إضافة سطر جديد. في حالة عدم القسمة، يتم طباعته مع مسافة في نهايته.

الحل باستخدام مشغل الشرط:
System.out.print((count % 10 == 0) ? (count + "\n") : (count + " "));


b.
سؤالb:
if (temperature > 90)
pay = pay * 1.5;
else
pay = pay * 1.1;


شرح:
هنا، إذا كانت درجة الحرارة أكبر من 90، سيتم ضرب pay في 1.5. إذا كانت أقل أو مساوية لـ 90، سيتم ضرب pay في 1.1.

الحل باستخدام مشغل الشرط:
pay = (temperature > 90) ? (pay * 1.5) : (pay * 1.1);


السؤال 2. عرض مخرجات البرامج:

a.
برنامج:
public class IfExample {
public static void main(String args[]) {
int x = 10, y = 20;
if (x < y) System.out.println("x is less than y");
x = x * 2;
if (x == y) System.out.println("x now equal to y");
x = x * 2;
if (x > y) System.out.println("x now greater than y");
if (x == y) System.out.println("you won't see this");
}
}


شرح:
1. يتحقق البرنامج من كون x أقل من y (10 < 20)، وبالتالي يقوم بطباعة "x is less than y".
2. يضاعف x ليصبح 20، ويتحقق مرة أخرى إذا كانت قيم x تساوي y فيطبع "x now equal to y".
3. يضاعف x مرة أخرى ليصبح 40 ويتحقق مما إذا كان أكبر من y، وبالتالي يقوم بطباعة "x now greater than y".
4. الأخطاء المتبقية لن تظهر، لذا لن تتم طباعة الجملة الأخيرة "you won't see this".



المخرج:
x is less than y
x now equal to y
x now greater than y


b.
لبرنامج:
switch(n) {
case 1:
System.out.println("The number is 1");
case 2:
System.out.println("The number is 2");
break;
default:
System.out.println("The number is not 1 or 2");
break;
}


شرح:
-
تتحقق العبارة switch من قيمة n.
- إذا كانت n تساوي 1، سيتم تنفيذ الكود داخل الحالة 1، لكن بدون break سيستمر البرنامج أيضاً في تنفيذ الحالة 2، مما يعني أنه سيطبع "The number is 1" و"The number is 2".
- إذا كانت n تساوي 2، سيتم طباعة "The number is 2" فقط، أما إذا كانت قيمة n غير 1 أو 2، ستتم طباعة "The number is not 1 or 2".

المخرجات بحسب قيمة n:
- إذا كانت n = 1:

The number is 1
The number is 2

- إذا كانت n = 2:
The number is 2

- إذا كانت n = 3 (أو أي قيمة غير 1 أو 2):
The number is not 1 or 2



السؤال 3. اكتب برنامجًا يقرأ عددًا غير محدد من الأعداد الصحيحة، ويحدد عدد القيم الموجبة والسلبية التي تمت قراءتها، ويحسب المجموع ومتوسط ​​القيم المدخلة (دون احتساب الأصفار).
import java.util.Scanner;

public class hh {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count = 0, posCount = 0, negCount = 0, total = 0;
double average = 0.0;
System.out.println("Enter integers (0 to stop):");
while (true) {
int number = in.nextInt();
if (number == 0) {
break;
}
count++;
total += number;
if (number > 0) {
posCount++;
} else {
negCount++;
}
}
if (count > 0) {
average = (double) total / count;
}
System.out.println("Total positive values: " + posCount);
System.out.println("Total negative values: " + negCount);
System.out.println("Total of entered values: " + total);
System.out.println("Average of entered values: " + average);

}
}

```


شرح البرنامج:
- يقوم البرنامج بإنشاء كائن من Scanner لقراءة المدخلات من المستخدم.
- يتم تعريف عدد من المتغيرات لحساب مجموع الأعداد الإيجابية والسلبية، الإجمالي والمتوسط.
- يدخل المستخدم أعدادًا صحيحة حتى يتم إدخال 0.
- لكل عدد، يقوم البرنامج بتحديث العد ومجموع القيم، بالإضافة إلى تحديث العداد للأعداد الإيجابية والسلبية.
- بعد انتهاء إدخال الأعداد، يقوم البرنامج بحساب المتوسط وعرض النتائج
.
👏31👍1