Dibandhingake karo Pascal - 1

"Hai. Jenengku Laga Bilaabo. Aku extraterrestrial lan dokter kapal iki. Muga-muga kita bakal dadi kanca sing apik."

"Aku uga."

"Ing planet asalku, kita nggunakake basa pamrograman Pascal sing luwih maju tinimbang basa Jawa sing mundur. Deleng perbandingan kode Jawa lan kode Pascal iki:"

Jawa Pascal
public class MyFirstClass
{
   public static void main(String[] args)
   {
      int a, b, c;
      String s1, s2;
      System.out.println("Enter two numbers");
      a = new Scanner(System.in).nextInt();
      b = new Scanner(System.in).nextInt();
      c = a + b;
      System.out.println("The sum is " + c);
   }
}
Program MyFirstProgram;
Var
   a, b, c: Integer;
   s1, s2: String;
Begin
   WriteLn("Enter two numbers");
   ReadLn(a);
   ReadLn(b);
   c := a + b;
   WriteLn("The sum is ", c);
End.

"Iki minangka program sing padha sing ditulis ing rong basa sing beda-beda. Nalika sampeyan bisa ndeleng, ana garis sing luwih sithik ing Pascal, sing dadi bukti yen Pascal luwih unggul tinimbang Jawa."

"Aku panginten conto iki bisa mbantu sampeyan luwih ngerti Jawa yen sampeyan wis tau ndeleng Pascal sadurunge."

"Ora, aku durung. Isih, menarik kanggo mbandhingake rong basa pemrograman."

"Cukup, aku bakal nerusake."

"Ing Pascal, kita nyelehake kode ing badan program, prosedur utawa fungsi. Ing Jawa, proses iki disederhanakake: awak program, prosedur, lan fungsi kabeh diganti karo fungsi sing disebut metode."

Jawa Pascal
Metode utama
public static void main(String[] args)
{
   System.out.println("Ho-ho-ho!");
}
Badan program
Begin
   WriteLn("Ho-ho-ho!");
End.
Fungsi/metode
double sqr(double a)
{
   return a * a;
}
Fungsi
Function Sqr(a: Real): Real
Begin
   Sqr := a * a;
End;
Fungsi karo jinis bali void
void doubleWrite(String s)
{
   System.out.println(s);
   System.out.println(s);
}
tata cara
Procedure DoubleWrite(s: String);
Begin
   WriteLn(s);
   WriteLn(s);
End;

"Ing kolom Pascal, aku weruh tembung 'badan program', 'fungsi', lan 'prosedur', nanging ing Jawa kabeh kasebut diarani metode. Sing rada aneh."

"Ya, kita extraterrestrials nemokake aneh banget. Nanging manungsa seneng nyawiji kabeh."

"Ing Jawa, kabeh kode minangka bagean saka metode, dadi sampeyan ora perlu nulis tembung Fungsi, kaya ing Pascal, kanggo ngumumake metode. "

"Kabeh iku prasaja banget. Yen baris kode katon kaya Tipe + Jeneng , iku deklarasi salah siji cara utawa variabel. Yen jeneng ngiring dening kurung, banjur deklarasi cara anyar . banjur dadi deklarasi variabel. "

"Deklarasi variabel lan metode ing Jawa meh padha. Deleng dhewe:"

Kode Katrangan
String name;
Variabel namekasebut diarani a String.
String getName()
{
}
Cara sing diarani getNamengasilake a String.

"Nanging ora kabeh. Ing Jawa, metode ora bisa diisolasi. Mesthi ana ing njero kelas. Dadi, nalika manungsa kudu nulis siji program cilik ing Jawa, mula kudu nggawe kelas, nyatakake metode utama , lan mung banjur bisa nulis kode ing metode . Wong bumi iki aneh banget!"

"Diego mampir sadurunge dina iki lan njaluk aku menehi tugas iki. Muga-muga sampeyan seneng."

1
tugas
Java Syntax,  tingkatwulangan
Dikunci
The great purge
Whoever wrote this program obviously did it in a hurry. Actually, that's not true: this program was written for educational purposes, and the author deliberately crammed in superfluous variables and simultaneously failed to declare necessary variables. We're going to correct this: Comment out the unnecessary variables, and declare the missing variables. Then the program will achieve universal harmony.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
Don't feel like it? Do it anyway.
Laziness afflicts even the best programmers. And not only programmers. Nevertheless, people have managed to become professionals by teaching themselves. So, we suggest not being lazy. Instead, display this slogan on the screen: "If you feel like it, do the task. If you don't feel like it, do it anyway". And to really remember this, display it 16 times.
5
tugas
Java Syntax,  tingkatwulangan
Dikunci
Square of a number
There are several ways to square a number. For example, some people write a number and then draw a square around it. This method is used by people who haven't studied anywhere. Everybody else has to multiply, remember the table of squares, ... or use a program. Your program should display the square of 5.
5
tugas
Java Syntax,  tingkatwulangan
Dikunci
As simple as 2+2
In a Java application, all the actions are performed by functions. Or more accurately, methods. In our program, a kind mentor has already implemented a method (that is, written the method's code) that can calculate the sum of two numbers. All you need to do is call this method with the arguments 2 and 2. You need to do this in the main method.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
Choose healthy food! Choose fruit!
Display the variables whose values are names of fruit. Display each variable on a new line.