الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

بليز مساعده

بدأه صعب تكراري في 7 ديسمبر 2012 · 5 رد · 530 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمه الله::

اخباركم...

الدكتوره اعطتنا سؤال باستخدام لغه الجافا حليته بس يطلع لي خطا

والسؤال write program to implement arithamatic operation and accept the input from the keyboard use switch statment??

لوسمحتو شوفو ايش الخطا في هذا البرنامج؟؟؟

هذي محاولاتي

Import java.util.*;

public class arthimatic {

public arthimatic() {

}

public static void main(String args[]){

int a,b;

String operation ;

Scanner ob=new Scanner(System.in);

System.out.println("enter the operation");

operation =ob.nextline();

System.out.println("enter frist number ");

a=ob.nextInt();

System.out.println("enter second number");

b=ob.nextInt();

switch(operation)

{

case '+':

System.out.println("the sum=" +(a+b));

case '-':

System.out.println("the sub=" +(a-b));

break;

case '*':

System.out.println("the multip=" +(a*b));

break;

case '%':

System.out.println("the moud=" +(a%b));

break;

case '/':

System.out.println("the dvid+(a/b));

break;

default:

System.out.println("bad command");

}

}

}

واريد برنامج بالجافا يطبع الارقام كذا

1

22

333

انا كتبت برنامج يطبع هذي الارقام بس مايطلع زي كذا

تكون المخرجات

1

23

45

مادري ايش اسوي؟؟

ومشكوورين

تم تعديل هذه المشاركة بواسطة صعب تكراري في 7 ديسمبر 2012 في 12:00

#2

تصحيح الكود :

import java.io.IOException;
import java.util.Scanner;

public class arthimatic {

    public static void main(String args[]) throws IOException {
        int a, b;
        char operation;
        Scanner ob = new Scanner(System.in);
        System.out.println("enter the operation");
        operation = (char) System.in.read();
        System.out.println("enter frist number ");
        a = ob.nextInt();
        System.out.println("enter second number");
        b = ob.nextInt();
        switch (operation) {
            case '+':
                System.out.println("the sum = " + (a + b));
                break;
            case '-':
                System.out.println("the sub = " + (a - b));
                break;
            case '*':
                System.out.println("the multip = " + (a * b));
                break;
            case '%':
                System.out.println("the moud = " + (a % b));
                break;
            case '/': {
                if (b == 0) {
                    System.out.println("Div By Zero !");
                } else {
                    System.out.println("the dvid = " + (a / b));
                }
            }
            break;
            default:
                System.out.println("bad command");
        }
    }
}

يمكنك أيضا قراءة المُدخلات كــ String و تخزين الحرف الأول في المتغير الحرفي operation هكذا :

String str = ob.nextLine();
char operation = str.charAt(0);

اقتباس
اريد برنامج بالجافا يطبع الارقام كذا

1

22

333

تفضلي :

public class display {

    public static void main(String args[]) {
        int max = 9;
        for (int i = 1; i <= max; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i);
            }
            System.out.println();
        }
    }
}
#3

السلام عليكم

import java.util.Scanner;


public class arthimatic {
public arthimatic() {
}
public static void main(String args[]){
int a,b;
String operation ;
Scanner ob=new Scanner(System.in);
boolean v=true;
do{
System.out.println("enter the operation");
operation =ob.next();
System.out.println("enter frist number ");
a=ob.nextInt();
System.out.println("enter second number");
b=ob.nextInt();

switch(operation)
{
case "+":
{System.out.println("the sum=" +(a+b));break;}
case "-":
{System.out.println("the sub=" +(a-b));break;}

case "*":
{System.out.println("the multip=" +(a*b));break;}

case "%":
{System.out.println("the moud=" +(a%b));
break;}
case "/":
{System.out.println("the dvid+(a/b)");
break;}
default:
{
System.out.println("bad command");
v=false;
}
}
}while(v==false);
}
}

كان عندك مشكل في ال types compatibility

ام السوال الثانى اين محاولتك

لا يمكننا مساعدتك بدون ان تحاول

ثالثا المرة القادم اختاري عنوان جيد و الا سيحذف موضوعك

لا تنسينى بدعاء يا بنيتي

تم تعديل هذه المشاركة بواسطة sahraoui dhelim في 7 ديسمبر 2012 في 13:06

#4

مشكوووورين الله يعطيكم العافيه

بس ي اخوي باقي مادرسنا زي كذا throws IOException

لمى اطبق بدون هذي المكتبه يطلع الخطا

found : java.lang.String

required : int

switch(operation)

والسوال الثاني هذي محاولاتي بس يطلع لي خطا

public class numb123 {

public numb123() {

}

public static void main(String args[])

{

int twoD[][]=new int [4][];

twoD[0]=new int[1];

twoD[1]=new int[2];

twoD[2]=new int[3];

twoD[3]=new int[4];

int i,j;

for(i=1;i<=4;i++)

for(j=1;j<=i;j++)

{

twoD[j]=i;

}

for(i=1;i<=4;i++){

for(j=1;j<=i;j++)

System.out.print(twoD[j] + "");

System.out.println();

}

}

}

الله يوفقكم ويجزاكم ربي الجنه...

#5

الكود بدون الــ IOException :

import java.util.Scanner;

public class arthimatic {

    public static void main(String args[]) {
        int a, b;
        Scanner ob = new Scanner(System.in);
        System.out.println("enter the operation");
        String str = ob.nextLine();
        char operation = str.charAt(0);
        System.out.println("enter frist number ");
        a = ob.nextInt();
        System.out.println("enter second number");
        b = ob.nextInt();
        switch (operation) {
            case '+':
                System.out.println("the sum = " + (a + b));
                break;
            case '-':
                System.out.println("the sub = " + (a - b));
                break;
            case '*':
                System.out.println("the multip = " + (a * b));
                break;
            case '%':
                System.out.println("the moud = " + (a % b));
                break;
            case '/': {
                if (b == 0) {
                    System.out.println("Div By Zero !");
                } else {
                    System.out.println("the dvid = " + (a / b));
                }
            }
            break;
            default:
                System.out.println("bad command");
        }
    }
}

بالنسبة للسؤال الثاني, هل جربتِ الحل الذي أعطيتك إياه ؟

#6

شكرا لك بحجم السماء ..

الله يعطيك العافيه..

مواضيع مشابهة