تعليم البرمجة
Java codes
- write a program in java that define a char variable and store a letter in this variable , then if the letter is capital print "Capital Letter" and if it's small print "Small Letter", and the out put must be as bellow
أكتب برنامجًا في جافا يحدد متغير نصي ويخزن حرفًا في هذا المتغير ، فإذا كان الحرف كبير أطبع
"Capital Letter"
وإذا كان حرفًا صغيرًا أطبع
"Small Letter" ،
ويجب أن يكون الإخراج كما يلي
public class test{
public static void main(String[]args){
char st_text = 'A';
if((int)st_text>64 && (int)st_text<97){
System.out.println("Capital Letter");
}
if((int)st_text>96 && (int)st_text<123){
System.out.println("Small Letter");
}
}
}
public static void main(String[]args){
char st_text = 'A';
if((int)st_text>64 && (int)st_text<97){
System.out.println("Capital Letter");
}
if((int)st_text>96 && (int)st_text<123){
System.out.println("Small Letter");
}
}
}
- write a java program in which you must define 2 integer variables with 2 values , and then switch the values with out using any other variable , and the out put must be as bellow
public class test{
public static void main(String[]args){
int num1 = 10,num2 = 20;
System.out.println("____________________ Before converting _____________________");
System.out.println();
System.out.println();
System.out.println("the first number is = "+num1);
System.out.println("the second number is = "+num2);
System.out.println();
System.out.println();
System.out.println("____________________ After converting _____________________");
System.out.println();
System.out.println();
num1 = num1+num2;
num2 = num1-num2;
num1 = num1-num2;
System.out.println("the first number is = "+num1);
System.out.println("the second number is = "+num2);
System.out.println();
System.out.println();
}
}
public static void main(String[]args){
int num1 = 10,num2 = 20;
System.out.println("____________________ Before converting _____________________");
System.out.println();
System.out.println();
System.out.println("the first number is = "+num1);
System.out.println("the second number is = "+num2);
System.out.println();
System.out.println();
System.out.println("____________________ After converting _____________________");
System.out.println();
System.out.println();
num1 = num1+num2;
num2 = num1-num2;
num1 = num1-num2;
System.out.println("the first number is = "+num1);
System.out.println("the second number is = "+num2);
System.out.println();
System.out.println();
}
}
- write a java program that check if a number It is divisible by 3 and 4 , and the out put must be as bellow
public class test{
public static void main(String[]args){
int num = 29;
if(num%3 == 0 && num%4 == 0){
System.out.println("Right number");
}
else{
System.out.println("Wrong number");
}
}
}
public static void main(String[]args){
int num = 29;
if(num%3 == 0 && num%4 == 0){
System.out.println("Right number");
}
else{
System.out.println("Wrong number");
}
}
}
No comments:
Post a Comment