دي باقي الأكواد الي احنا شرحناها و مطبقناش عليها
دا اول واحد عشان نطبع المثلث بال * بطرقة ال for
دا اول واحد عشان نطبع المثلث بال * بطرقة ال for
- CODE: تحديد الكل
public class array
{
public static void main(String args[])
{
for(int x =0 ; x<=4 ; x++)
{
for(int y = 4 ; y>=4-x ; y--)
{
System.out.print("*");
}
System.out.println();
}
}
}
Using For
- CODE: تحديد الكل
public class Astric
{
public static void main(String args[])
{
for(int x =0 ; x<=4 ; x++)
{
for(int y = 0 ; y<=4-x ; y++)
{
System.out.print("*");
}
System.out.println();
}
}
}
Using While
- CODE: تحديد الكل
class While
{
public static void main(String args[])
{
int y=1;
while (y<=5)
{
int i =1;
while (i<=(6-y))
{
System.out.print("*");
i++;
} // End Of The While
System.out.println();
y++;
} // End of the First While
}
}
Using Do While
- CODE: تحديد الكل
class while
{
public static void main(String args[])
{
int z=1;
do
{
System.out.println();
int i=1;
do {
System.out.print("*");
i++;
} while (i<=(6-z));
z++;
}while (z<=5);
System.out.println();
}
}
Using Switch To Print
- CODE: تحديد الكل
import java.util.Scanner;
class Switch {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);//create object from Scanner class
System.out.println("Enter Month Number :");
int month= sc.nextInt();//read the number from the user (Like -----console.readeline();)
String season;
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
break;
case 3:
case 4:
case 5:
season = "Spring";
break;
case 6:
case 7:
case 8:
season = "Summer";
break;
case 9:
case 10:
case 11:
season = "Autumn";
break;
default:
season = "Bogus Month";
}
System.out.println("Month is in the " + season + ".");
}
}
Operator Using Scanner
- CODE: تحديد الكل
import java.util.Scanner;
public class Scanner
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Number :");
int x= sc.nextInt();
System.out.println("Enter Second Number :");
int y=sc.nextInt();
int z = x*y;
System.out.println("The Result Is :" + z);
}
}
Revers Word
- CODE: تحديد الكل
public class Revers{
public static void main(String[] args){
String s = "Java";
int length = s.length();
System.out.println(length);
for (int i=length-1;i>=0;i--)
System.out.print(s.charAt(i));
System.out.println();
}
}
