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

من يساعدني في تحويل هذا البرنامج الى لغة Java

بدأه WhiteShark في 14 أبريل 2008 · 2 رد · 413 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم اخواني ..

اني جديد على لغة جافا و اريدكم في خدمه و هي تحويل هذا البرنامج من لغة C الى Java ومشكورين

#include <stdio.h>
#include <ctype.h >


void DisplayMenu()
{
  printf("Enter (a) to print my name\n");
  printf("Enter (d) to print tutorial time\n");
  printf ("Enter (f) to display numbers\n");
  printf("Enter (q) to quit\n");
  return;
}


void GetChoice(char &choice)
{
  scanf("%c%*c", &choice);
  choice = tolower(choice);
  return;
}


void PrintName()
{
  printf("My name is Mohammed\n");
  return;
}


void PrintTut()
{
  printf("Tutorial time is 11:30 am, Tuesday\n");
  return;
}


void DisplayNum()
{
  int num,i;

  printf("Enter a number >=1 and <=50\n");
  scanf("%d%*c", &num);

  if (num>=1 && num<=50)
  {
     for (i=0;i<=num;i++)
     {
      printf(" %d", i);
     }
   printf("\n");
  }

  else
      printf("Invalid number\n");

  return;
}


void DoChoice(char choice)
{

  switch(choice)
  {
  case 'a':
    PrintName();
    break;

  case 'd':
     PrintTut();
     break;

  case 'f':
     DisplayNum();
     break;

  case 'q':
     default:
     printf("Exit");
  }
return;
}

int main()

{

  char choice;
  do
  {
     DisplayMenu();
     GetChoice(choice);
     DoChoice(choice);
  }while(choice != 'q');

getchar();
return(0);
}

تم تعديل هذه المشاركة بواسطة WhiteShark في 14 أبريل 2008 في 13:15

#2
import java.util.Scanner;

class MyProg 
{
	Scanner in;
	public MyProg ()
	{
		in = Scanner(System.in);
	}
	void DisplayMenu()
	{
		System.out.print("Enter (a) to print my name\n");
		System.out.print("Enter (d) to print tutorial time\n");
		System.out.print("Enter (f) to display numbers\n");
		System.out.print("Enter (q) to quit\n");
	}

	void GetChoice(char choice)
	{
		choice =  in.nextChar();
		choice = toLower(choice);
	}
	char toLower(char choice)
	{
		String c = "" + choice;
		c = c.toLowerCase();
		return c.charAt(0);
	}
	void PrintName()
	{
		System.out.print("My name is Mohammed\n");
	}
	void PrintTut()
	{
		System.out.print("Tutorial time is 11:30 am, Tuesday\n");
	}
	void DisplayNum()
	{
		int num,i;
		System.out.print("Enter a number >=1 and <=50\n");

		num = in.nextChar();

		if (num>=1 && num<=50)
		{
			for (i=0;i<=num;i++)
			{
				System.out.print(i);
			}
			System.out.print("\n");
		}
		else
		System.out.print("Invalid number\n");

	}
	void DoChoice(char choice)
	{

		switch(choice)
		{
			case 'a':
			PrintName();
			break;

			case 'd':
			PrintTut();
			break;

			case 'f':
			DisplayNum();
			break;

			case 'q':
			default:
			System.out.print("Exit");
		}
	}
	public static void main(String [] args)
	{
		char choice;
		do
		{
			DisplayMenu();
			GetChoice(choice);
			DoChoice(choice);
		}
		while(choice != 'q');
	}

}
#3

مشكووور على المساعده و انا كتير استفدت

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