Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 35

Q1LT1/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package q1.lt1;

/**

* @author Star Computer

*/

public class Q1LT1 {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

System.out.println("Hello");

System.out.println("Taimoor Ahmed");

// TODO code application logic here

}
}

Q2LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q2.lt1;

/**
*
* @author Star Computer
*/
public class Q2LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("40/3=");
System.out.println(40/3);
// TODO code application logic here
}

Q3LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q3.lt1;
/**
*
* @author Star Computer
*/
public class Q3LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Test Data");
System.out.println("a.-2+4*3=");
System.out.println(-2+4*3);
System.out.println("b.(52+7)%7=");
System.out.println((52+7)%7);
System.out.println("c.21+-4*7/9=");
System.out.println(21+-4*7/9);
System.out.println("d.4+11/34*3-8%3=");
System.out.println(4+11/34*3-8%3);

// TODO code application logic here


}
}

Q4LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q3.lt1;

/**
*
* @author Star Computer
*/
public class Q3LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Test Data");
System.out.println("a.-2+4*3=");
System.out.println(-2+4*3);
System.out.println("b.(52+7)%7=");
System.out.println((52+7)%7);
System.out.println("c.21+-4*7/9=");
System.out.println(21+-4*7/9);
System.out.println("d.4+11/34*3-8%3=");
System.out.println(4+11/34*3-8%3);

// TODO code application logic here


}

}
Q5LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q5lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q5LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("enter a number");
int n=sc.nextInt();
for(int i=1;i<=10;i++)
System.out.println(n+"*"+i+"="+n*i);
// TODO code application logic here
}
}

Q6LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q6lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q6LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a,b,temp;
System.out.println("enter two numbers");
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
System.out.println("before swap"+a+" "+b);
temp=a;
a=b;
b=temp;
System.out.println("after swap"+a+" "+b);
// TODO code application logic here
}
}

Q7LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q7lt1;
import java.util.Scanner;
/**
*
* @author Star Computer
*/
public class Q7LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int number1;
int number2;
System.out.printf("enter first integer");
number1=sc.nextInt();
System.out.printf("enter second integer");
number2=sc.nextInt();
if(number1 != number2)
System.out.printf("%d != %d\n" , number1 , number2);
if (number1 < number2)
System.out.printf("%d < %d\n",number1,number2);
if (number1 <= number2)
System.out.printf("%d <= %d\n" , number1 , number2);
// TODO code application logic here
}
}

Q8LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q8lt1;

/**
*
* @author Star Computer
*/
public class Q8LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
for(int i=1;i<=100;i++)
if(i%2 != 0)
System.out.println(i);
// TODO code application logic here
}

Q9LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q9lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q9LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("enter number");
int n=in.nextInt();
if(n % 2 == 0)
{
System.out.println(1);
}
else
{
System.out.println(0);
}
// TODO code application logic here
}
}

Q10LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q10lt1;

/**
*
* @author Star Computer
*/
public class Q10LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("\ndivided by 3: ");
for(int i=1;i<100;i++)
{
if(i%3==0)
System.out.print(i+" , ");
}
System.out.print("\ndivided by 5:");
for(int i=1;i<100;i++)
{
if(i%5==0)
System.out.print(i+" , ");
}
System.out.print("\n\ndivided by 3 & 5:");
for(int i=1;i<100;i++)
{
if(i%3==0&&i%5==0)
System.out.print(i+" , ");
}
System.out.print("\n");
// TODO code application logic here
}
}

Q12LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q12lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q12LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

Scanner in=new Scanner(System.in);


System.out.println("enter a number:");
int x=in.nextInt();
System.out.println(result(x));
}
public static int result(int num){
int ctr=0;
for(int i=1;i<=(int)Math.sqrt(num);i++){
if(num%i==0 && i*i!=num){
ctr+=2;
}
else if(i*i==num){
ctr++;
}
}
return ctr;
// TODO code application logic here
}
}

Q13LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q13lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q13LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("enter first num:");
int num1 =in.nextInt();
System.out.println("enter second num:");
int num2 =in.nextInt();
System.out.println("enter third num:");
int num3 =in.nextInt();
if(num1 > num2)
if(num1 > num3)
System.out.println("greatest:" + num1);
if(num2 > num1)
if(num2 > num3)
System.out.println("greatest:" +num2);
if(num3 > num1)
if(num3 > num2)
System.out.println("greatest:" +num3);
// TODO code application logic here
}
}

Q14LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q14lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q14LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int i,n=0,s=0;
double avg;
{
System.out.println("enter five number:");
}
for(i=0;i<5;i++)
{
Scanner in=new Scanner(System.in);
n=in.nextInt();

s +=n;
}
avg=s/5;
System.out.println("sum of five number is:"+s+"\n Average is: " +avg);
// TODO code application logic here
}
}

Q15LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q15lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q15LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int i,n;
System.out.println("Input number of terms:");
Scanner in=new Scanner(System.in);
n = in.nextInt();

for(i=1;i<=n;i++);
{
System.out.println("number is: " +i+" cube of " +i+"is:"+(i*i*i));
// TODO code application logic here
}

}
Q16LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q16lt1;

/**
*
* @author Star Computer
*/
public class Q16LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

String str = "Hello";


for(int i=0; i<str.length();i++){
char ch =str.charAt(i);
System.out.println("Character at "+i+" postion: "+ch);
// TODO code application logic here
}
}

Q17LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q17lt1;

/**
*
* @author Star Computer
*/
public class Q17LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

String line = "This Website is aw3som3.";


int vowels = 0, consonants = 0, digits = 0, spaces = 0;
line = line.toLowerCase();
for(int i=0;i<line.length();i++){
char ch = line.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
++vowels;
}
else if((ch >='a' && ch <= 'z')){
++consonants;
}
}

System.out.println("Vowels:" + vowels);
System.out.println("Constants:" + consonants);
// TODO code application logic here
}
}

Q18LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q18lt1;

/**
*
* @author Star Computer
*/
public class Q18LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

String main_string = "Python 3.0";


String word = "tutorial";
System.out.println(main_string.substring(0, 7)+ word +
main_string .substring(6));
// TODO code application logic here
}

Q20LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q20lt1;

/**
*
* @author Star Computer
*/
public class Q20LT1 {

static byte b;
static short s;
static int i;
static long l;
static float f;
static double d;
static char c;
static boolean bl;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("The default values of primitive data types are:");
System.out.println("Byte :"+b);
System.out.println("Short :"+s);
System.out.println("Int :"+i);
System.out.println("Long :"+l);
System.out.println("Float :"+f);
System.out.println("Double :"+d);
System.out.println("Char :"+c);
System.out.println("Boolean :"+bl);
// TODO code application logic here
}

Q23LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q23lt1;

/**
*
* @author Star Computer
*/
public class Q23LT1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int num = 10;


long factorial = 1;
for(int i = 1; i <= num; ++i)
{
factorial *= i;

}
System.out.printf("Factorial of %d = %d", num, factorial);
// TODO code application logic here
}
}

Q25LT1
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q25lt1;
import java.util.Scanner;

/**
*
* @author Star Computer
*/
public class Q25LT1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int n, reverse = 0;
System.out.println("Enter number to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while( n != 0 )
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of entered number is "+reverse);
// TODO code application logic here
}

You might also like