البرمجة بالعراقي
Open in Telegram
هاي قناة سوينها ل طلاب علوم الحاسوب حتى نتعاون بيناتنا ونتعلم كل ما يتعلق بالبرمجة وايضا كلشي من ادوات ذكاء اصطناعي و مشاريع و بوتات رابط كروب مجموعة https://t.me/learn_javaaa
Show more833
Subscribers
No data24 hours
-57 days
-1330 days
Posts Archive
Scanner mu = new Scanner(System.in);
int reverse=0,n;
n = mu.nextInt();
while(n != 0)
{ reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println(reverse);
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
int n=mu.nextInt();
int a[]=new int[n];
int b[]=new int[n];
int c[]=new int[n];
for (int i = 0; i <n; i++) {
a[i]=mu.nextInt();
}
//العنصر الاول نفسة بدون تكعيب
b[0]=a[0];
for (int i = 1; i <n; i++){
b[i]= (int)Math.pow(a[i],3);
}
System.out.println("Elements of Array B are: \n");
for (int i = 0; i <b.length; i++) {
System.out.print(b[i]+" ");
}
System.out.println("Elements of Array C are: \n");
for (int i = 0; i <c.length; i++) {
c[i]=a[i]*b[i];
System.out.print(c[i]+" ");
}
السؤال يتكلم عن مصفوفة عادية اسمها A
ومصفوفة B تساوي تكعيب كل عنصر في B ما عدا العنصر الاول بدون تكعيب
مصفوفة C عناصرها ضرب العناصر المتقابلة في A,B
package tupac;
import java.util.Scanner;
public class Tupac {
static boolean prime(int n){
boolean f=true;
for (int i = 2; i <n; i++) {
if(n%i==0)
f= false;
}
return f;
}
public static void main(String[] args) {
Scanner mu = new Scanner(System.in);
System.out.print("enter n : ");
int n=mu.nextInt();
for (int i = 2; i <=n/2; i++)
{
if(prime(n-i))
System.out.println(n+"="+i+"+"+(n-i));
}
}}
class Course{
String name;
int time,numbers;
void setValue(String name,int time,int numbers){
this.name=name;
this.time=time;
this.numbers=numbers;
}
void courseInfo(){
System.out.println(name+" course "+numbers+" "+time+":00 PM \n ");
}
void welcomMsg(){
System.out.println("welcome to could center/training section \n");
}
}
public class Ms {
public static void main(String[] args) {
Course c=new Course();
Course c1=new Course();
Course c2=new Course();
c.welcomMsg();
c.setValue("java", 4, 10);
c1.setValue("PHP", 3, 5);
c2.setValue("C++", 1, 8);
c.courseInfo();
c1.courseInfo();
c2.courseInfo();
سؤال ١٣
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 min=a[1],s=a[0];
for (int i = 0; i <n; i++)
{
if(s>a[i])
s=a[i];
}
for (int i = 0; i <n; i++)
{ if(a[i]<min && a[i]>s)
min=a[i];
}
System.out.println("The Second smallest element in the array is :"+min);
سؤال ١٢
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 max=a[0],s=a[0];
for (int i = 0; i <n; i++)
{
if(a[i]>s)
s=a[i];
}
for (int i = 0; i <n; i++)
{ if(max<a[i]&&a[i]<s)
max=a[i];
}
System.out.println("The Second largest element in the array is : "+max);
س11 حذف عنصر
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
n=mu.nextInt();
int a[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
System.out.print("select position of element that you wanna delete: ");
int pos=mu.nextInt();
int b[]=new int[n-1];
for(int i=0; i<pos; i++)
b[i]=a[i];
for(int i=pos; i<n-1; i++){
b[i]=a[i+1];
}
for (int i = 0; i <b.length; i++) {
System.out.print(b[i]+" ");
}
س10 اضافة عنصر
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
n=mu.nextInt();
int a[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
System.out.print("select position of element that you wanna add: ");
int pos=mu.nextInt();
int b[]=new int[n+1];
for(int i=0; i<pos; i++)
b[i]=a[i];
for(int i=pos; i<n+1; i++){
b[i]=a[i-1];
if(i==pos){
System.out.print("add element: ");
b[i]=mu.nextInt();
}}
for (int i = 0; i <b.length; i++) {
System.out.print(b[i]+" ");
}
س9 بطريقة 2 طريقة الدوال
static int n;
static int max(int a[]) {
int m=a[0];
for (int i = 0; i <n; i++)
if(a[i]>m)
m=a[i];
return m;
}
static int min(int a[]) {
int m=a[0];
for (int i = 0; i <n; i++)
if(a[i]<m)
m=a[i];
return m;
}
public static void main(String[] args) {
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
n=mu.nextInt();
int a[]=new int[n];
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
System.out.println("Maximum element is :"+max(a));
System.out.println("Minimum element is :"+min(a));
س9
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
int n=mu.nextInt();
int a[]=new int[n];
int max=0,min=999;
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
for (int i = 0; i <n; i++){
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];}
System.out.println("Maximum element is :"+max);
System.out.println("Minimum element is :"+min);
س8 معرفة عدد تكرار العنصر
Scanner mu = new Scanner(System.in);
System.out.print("enter size of the array: ");
int n=mu.nextInt();
int a[]=new int[n];
int k=1;
for (int i = 0; i <n; i++) {
System.out.print("element - "+i+": ");
a[i]=mu.nextInt();
}
for (int i = 0; i <n; i++) {
boolean f=true;
for (int j = i+1; j <n; j++){
if(a[i]==a[j])
f=false;
}
if(f){
System.out.println(a[i]+" occurs 1 times "); }
else{
System.out.println(a[i]+" occurs "+ ++k +"times ");
}
}
س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]+" ");
}
س6 دمج مصفوفتين
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();
}
System.out.print("Input the number of elements in the second array: ");
int s=mu.nextInt();
int b[]=new int[s];
for (int i = 0; i <s; i++) {
System.out.print("element - "+i+": ");
b[i]=mu.nextInt();
}
int z=s+n;
int c[]=new int[z],k=0;
for (int i = 0; i <n; i++) {
c[k]=a[i]; k++;
}
for (int i = 0; i <s; i++) {
c[k]=b[i]; k++;
}
for (int i = 0; i < k; i++) {
System.out.print(c[i]+" ");
}
س5 ايجاد العناصر الغير المكرره
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();
}
System.out.println("\n The unique elements found in the array are:");
for (int i = 0; i <n; i++) {
boolean f=true;
for (int j =0; j <n; j++)
if(a[i]==a[j]&&i!=j){
f=false;
break;
}
if(f)
System.out.println(a[i]+" ");
}
