Lab Assignments Codes
Q Muhammad Shahzad Khalil
Course InStructor: Ms Asma
Sep 17, 2012
Code 1 :
public class First {
public static boolean A (int num){
for(int i=0; i>=num; i++){
if(num % 4==0 && num % 100 != 0 || num % 4 == 0 && num % 100 == 0 && num % 400 == 0){
return (true);
}
}
return (false);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(A(16));
}
}
Code 2:
public class armstrong {
public static void main(String[] args) {
for(int i=100;i<1000;i++){
int a=i%10;
int i1 = i/10;
int b = i1%10;
int i2 = i1/10;
int c = i2%10;
a=a*a*a;
b=b*b*b;
c=c*c*c;
int d=a+b+c;
if(d == i){
System.out.println(i);
}
}
}
}
public static void main(String[] args) {
for(int i=100;i<1000;i++){
int a=i%10;
int i1 = i/10;
int b = i1%10;
int i2 = i1/10;
int c = i2%10;
a=a*a*a;
b=b*b*b;
c=c*c*c;
int d=a+b+c;
if(d == i){
System.out.println(i);
}
}
}
}
Code 3 :
import java.util.Random;
public class randomNum{
public static void main Divisor (Int num){
if(num%2==0){
System.out.print(num + “ is divisible by two”);
}
if(num%3==0){
System.out.print(num + “ is divisible by three”);
}
if(num%5==0){
System.out.print(num + “ is divisible by five”);
}
if(num%6==0){
System.out.print(num + “ is divisible by six”);
}
if(num%10==0){
System.out.print(num + “ is divisible by ten”);
}
if(num%15==0){
System.out.print(num + “ is divisible by fifteen”);
}
if(num%30==0){
System.out.print(num + “ is divisible by thirty”);
}
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random rand= new Random();
int a= rand.nextInt();
Divisor(a);
}
Code 4 :
public static void month_checker (String month ) {
int n = 0;
String a = month.substring(0,3);
String out = a.toUpperCase();
System.out.println(out);
if (out.equals("JAN")) n=1;
if (out.equals("FEB")) n=2;
if (out.equals("MAR")) n=3;
if (out.equals("APR")) n=4;
if (out.equals("MAY")) n=5;
if (out.equals("JUN")) n=6;
if (out.equals("JUL")) n=7;
if (out.equals("AUG")) n=8;
if (out.equals("SEP")) n=9;
if (out.equals("OCT")) n=10;
if (out.equals("NOV")) n=11;
if (out.equals("DEC")) n=12;
if (n!=0) System.out.println("The number of the month is"+" "+n);
else System.out.println("This is not a valid month");
int n = 0;
String a = month.substring(0,3);
String out = a.toUpperCase();
System.out.println(out);
if (out.equals("JAN")) n=1;
if (out.equals("FEB")) n=2;
if (out.equals("MAR")) n=3;
if (out.equals("APR")) n=4;
if (out.equals("MAY")) n=5;
if (out.equals("JUN")) n=6;
if (out.equals("JUL")) n=7;
if (out.equals("AUG")) n=8;
if (out.equals("SEP")) n=9;
if (out.equals("OCT")) n=10;
if (out.equals("NOV")) n=11;
if (out.equals("DEC")) n=12;
if (n!=0) System.out.println("The number of the month is"+" "+n);
else System.out.println("This is not a valid month");
_______________________________________________________________________________
Code 5
import java.util.Scanner;
public class fifthques {
public static void main(String[] args) {
Scanner var5= new Scanner(System.in);
String name;
System.out.println("Enter ur name");
name = var5.next();
double phy;
double maths;
double eng;
double comp;
double ipl;
double percent;
System.out.println("Enter ur Physics Marks");
phy= var5.nextDouble();
System.out.println("Enter ur Maths Marks");
maths= var5.nextDouble();
System.out.println("Enter ur English Marks");
eng= var5.nextDouble();
System.out.println("Enter ur Computer Marks");
comp= var5.nextDouble();
System.out.println("Enter ur IPL Marks");
ipl= var5.nextDouble();
System.out.println("Your Name is " + name );
System.out.println("Your Physics Marks are " + phy);
System.out.println("Your Maths Marks are " + maths);
System.out.println("Your English Marks are " + eng);
System.out.println("Your Computer Marks are " + comp);
System.out.println("Your IPL Marks are " + ipl);
System.out.println("Your percentage is " +(percent=(((phy+maths+eng+comp+ipl)/500) *100) ));
}
}
Code 5
import java.util.Scanner;
public class fifthques {
public static void main(String[] args) {
Scanner var5= new Scanner(System.in);
String name;
System.out.println("Enter ur name");
name = var5.next();
double phy;
double maths;
double eng;
double comp;
double ipl;
double percent;
System.out.println("Enter ur Physics Marks");
phy= var5.nextDouble();
System.out.println("Enter ur Maths Marks");
maths= var5.nextDouble();
System.out.println("Enter ur English Marks");
eng= var5.nextDouble();
System.out.println("Enter ur Computer Marks");
comp= var5.nextDouble();
System.out.println("Enter ur IPL Marks");
ipl= var5.nextDouble();
System.out.println("Your Name is " + name );
System.out.println("Your Physics Marks are " + phy);
System.out.println("Your Maths Marks are " + maths);
System.out.println("Your English Marks are " + eng);
System.out.println("Your Computer Marks are " + comp);
System.out.println("Your IPL Marks are " + ipl);
System.out.println("Your percentage is " +(percent=(((phy+maths+eng+comp+ipl)/500) *100) ));
}
}
No comments:
Post a Comment