البرمجة بالعراقي
Open in Telegram
هاي قناة سوينها ل طلاب علوم الحاسوب حتى نتعاون بيناتنا ونتعلم كل ما يتعلق بالبرمجة وايضا كلشي من ادوات ذكاء اصطناعي و مشاريع و بوتات رابط كروب مجموعة https://t.me/learn_javaaa
Show more833
Subscribers
No data24 hours
-57 days
-1330 days
Posts Archive
س7
دمج مصفوفتين بنفس اللوب
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
int n=mu.nextInt();
int a[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
int b[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
b[i]=mu.nextInt();
}
int z=n+n;
int c[]=new int[z],k=0;
for (int i = 0; i <n; i++) {
c[k]=a[i]; k++;
c[k]=b[i]; k++;
}
System.out.println("\n The merged array in decending order is:");
for (int i = 0; i < k; i++) {
System.out.print(c[i]+" ");
}
سؤال ٢
مطلوب
نعمل مصفوفتين منفصلات وحده للعناصر الزوجيه والثانية للفردية
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
int n=mu.nextInt();
int a[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
int even[]=new int[n], k=0;
int odd[]=new int[n], z=0;
for (int i = 0; i <n; i++) {
if(a[i]%2==0){
even[k] = a[i]; k++;
}
else {
odd[z] = a[i]; z++;
}
}
System.out.println("\n The Even elements are : ");
for (int i = 0; i <k; i++) {
System.out.print(even[i]+" ");
}
System.out.println("\n The Odd elements are : ");
for (int i = 0; i <z; i++) {
System.out.print(odd[i]+" ");
}
فرع b
package tupac;
public class Tupac {
static int [] set(int [] a3)
{a3[1] = 7
;return a3;
}
static void process()
{int [] a1 = {3,4,5 };
System.out.print(a1[0] + a1[1] + a1[2]+" ");
int [] a2 = set(a1);
System.out.println(a2[0] + a2[1] + a2[2]);}
public static void main(String[] args) {
process();
}}
اول ما يطبع قيمة ال a الاولى a=6
والثانية a = 24
System.out.print(a)
بدون ماينزل سطر يعني يدمجهن سوى يصيرن عدد واحد
624
شباب اول خطوة
b=2
a=2
a*=b+1
a*= 2+1
2*=3
a=2*3
[a=6]
b++
ثاني خطوة
b=3
a=6
a*=b+1
a*= 3+1
6*=4
a=6*4
[ a= 24]
q2
int a,b=1;
a=++b;
for (int i = 1; i < 3; i++) {
a*=b+1;
b++;
System.out.print(a);
}
q3
package lab;
import java.util.Scanner;
class Hospital{
String hName, dName, sName;
Hospital (String hName){
this.hName=hName;
}
void sick(String sName){
this.sName=sName;
}
void doctor(String dName ){
this.dName=dName;
}
void display(){
System.out.println("\n Hospital Name= "+hName+"\n Doctor Name= "+dName+ "\n sick Name= "+sName );
}
}
class Clinic extends Hospital{
String cName,address;
public Clinic(String hName,String cName ,String address) {
super(hName);
this.cName=cName;
this.address=address;
}
@Override
void display() {
super.display();
System.out.println("Clinic Name= "+cName+"\n address= "+address);
}
}
public class Lab {
public static void main(String[] args) {
Clinic cl[]=new Clinic[3];
String c,h,d,s,a;
Scanner Scn=new Scanner(System.in);
for(int i=0;i<3;i++)
{
System.out.print("Hospital name:");
h=Scn.next();
System.out.print("Clinic name:");
c=Scn.next();
System.out.print("Address:");
a=Scn.next();
cl[i]=new Clinic(h,c,a);
System.out.print("Doctor name:");
d=Scn.next();
System.out.print("Sick name:");
s=Scn.next();
cl[i].sick(s);
cl[i].doctor(d);
}
for(int i=0;i<3;i++)
{
cl[i].display();
System.out.println("\n------------------------------------\n");
}
}}
اذا تلاحظ
دوال السيت نستدعيها بالجزء الmain ونخلي قيم بين قوسين هذا شغلها الدوال السيت
والget نطبعها لان ترجع القيمة الي خليناها بالسيت
بس امشوا ع الحل النموذجي للكلية بالنسبة اللي عندهم امتحان
المفروض هذا الحل بدون كونستركتر
package ms;
import java.util.Scanner;
class Animals{
Boolean vegetarian;
String eats;
int noOflegs;
Boolean isVegetarian(){
return vegetarian;
}
void setVegetarian(Boolean vegetarian){
this.vegetarian=vegetarian;
}
String getEats(){
return eats;
}
void setEats(String eats){
this.eats=eats;
}
int getNoOflegs(){
return noOflegs;
}
void setNoOflegs(int noOflegs){
this.noOflegs=noOflegs;
}}
class Cat extends Animals{
String color;
String getColor(){
return color;
}
void setColor(String color){
this.color=color;
}
}
public class Ms {
public static void main(String[] args) {
Cat c=new Cat();
c.setColor("black");
c.setEats("fish");
c.setVegetarian(false);
c.setNoOflegs(4);
System.out.println(" color: "+c.color+"\n eats: "+c.getEats()+"\n is vegetarian? "+ c.isVegetarian()+"\n noOflegs= "+c.getNoOflegs());
}}
معلومة دوال set و get تسند القيم بمكان الكونستركتر محاجه تعمل كونستركتر، بس امشوا ع حل الكلية 🙁
هذا السؤال يناقض الكيانية ليش؟
لأن بي دوال set و get محاجه نعمل كونستركتر ونخلي متغيرات وقيم ابتدائيه
لأن دوال set و get تغنيك عن الكونستركتر
بس تستدعي دالة set وتحط قيمة بين قوسين ودالة get تطبعها
