JAVA(OOP) 3rd Sem Practical 3
Practical 3
A-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
import java.util.Scanner;
public class prac1 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter Your Number=");
int a=sc.nextInt();
Random r=new Random();
r.getdata(a);
}
}
class Random
{
void getdata(int n)
{
float d=(float)Math.random();
float x=n*d;
System.out.println("Your Number is="+x);
}
}
B-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
import java.util.Scanner;
public class prac2 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter Your Number=");
int a=sc.nextInt();
type r=new type();
r.getdata(a);
}
}
class type
{
void getdata(int n)
{
float d=(float)Math.random();//Explicit type casting
float x=n*d;//Implicit type casting from int to float
System.out.println("Your Number is="+x);
}
}
C-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
import java.util.Scanner;
public class prac3 {
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
System.out.print("Enter First Number=");
int a=sc.nextInt();
System.out.print("Enter Second Number=");
int b=sc.nextInt();
maximum m =new maximum();
m.getdata(a,b);
m.method();
int c=m.method();
System.out.println("Maximum Number is= "+c);
}
}
class maximum
{
int a,b;
void getdata(int x,int y)
{
a=x;
b=y;
}
int method()
{
int w=(a>b?a:b);
return w;
}
}
D-
/*
* 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 practical3;
import java.util.Scanner;
/**
*
* @author uvpcecollege.blogspot.com
*/
public class prac4 {
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
System.out.print("Enter First Number=");
int a=sc.nextInt();
System.out.print("Enter Second Number=");
int b=sc.nextInt();
System.out.print("Enter Third Number=");
int c=sc.nextInt();
Maxim m =new Maxim();
m.getdata(a,b,c);
m.method();
}
}
class Maxim
{
int a,b,c;
void getdata(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void method()
{
int w=(a>b?(a>c?a:c):(b>c?b:c));
System.out.println("Maximum Number is= "+w);
int u=(a<b?(a<c?a:c):(b<c?b:c));
System.out.println("Minimum Number is= "+u);
}
}
E-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
public class prac5 {
public static void main(String args[])
{
int i=4;
System.out.println (++ i);//i=++i because of prefix i=5
System.out.println (i);//no operation i=5
System.out.println (i++);//i=i++ first i asigns in i then postfix i=5
System.out.println (i);//because of postfix i=6
System.out.println (--i);//becaise if pretfix i=5
System.out.println (i--);//i=i++ first i asigns in i then prefix i=5
System.out.println (i);//because of pretfix i=4
}
}
F-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
public class prac6 {
public static void main(String args[])
{
double x=9,y=2.3,z=5.2;
System.out.println(x + y * z);
System.out.println(x / y * z);
System.out.println(x / 2 + y / 2);
System.out.println(x % 5 * 3 + 1);
System.out.println(5*3%x);
System.out.println((y + 3) * 2);
System.out.println(z / (1 + 1));
/* 1.( ) 2./ 3.* 4.+ 5.- */
}
}
G-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
import java.util.Scanner;
public class prac7 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter Marks:");
int a=sc.nextInt();
average av=new average();
av.getdata(a);
}
}
class average
{
void getdata(int n)
{
int x=n/10;
switch(x)
{
case 10:
case 9:
System.out.println("Grade is = A+");
break;
case 8:
System.out.println("Grade is = A");
break;
case 6:
System.out.println("Grade is = B+");
break;
case 5:
System.out.println("Grade is = B");
break;
case 4:
System.out.println("Grade is = C+");
break;
case 3:
case 2:
case 1:
System.out.println("Grade is = C");
break;
}
}
}
H-
/*
* 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 practical3;
import java.util.Scanner;
/**
*
* @author uvpcecollege.blogspot.com
*/
public class prac8 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter your Number:");
int a=sc.nextInt();
guess g=new guess();
g.getdata(a);
}
}
class guess
{
void getdata(int x)
{
if(x<250000)
{
System.out.println("Value is " +x+ " Its Too Low");
}
else if(x>375000)
{
System.out.println("Value is " +x+ " Its Too High");
}
else
{
System.out.println("Value is " +x+ " Its Moderate");
}
}
}
I-
/*
* 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 practical3;
/**
*
* @author uvpcecollege.blogspot.com
*/
import java.util.Scanner;
public class prac9 {
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.print("Enter Any Number=");
int a=in.nextInt();
power x=new power();
x.getdata(a);
}
}
class power
{
void getdata(int n)
{
for(int i=1;i<=n;i++)
{
int x=2*i;
System.out.println(" "+x);
}
}
}
0 comments:
Post a Comment