0% found this document useful (0 votes)
15 views

Java 531

The document contains code for a Java program that takes input of different data types like integer, string, float etc and stores them in variables of corresponding data types. It then prints the values of all variables to display the data entered by the user.

Uploaded by

217y1a66g4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Java 531

The document contains code for a Java program that takes input of different data types like integer, string, float etc and stores them in variables of corresponding data types. It then prints the values of all variables to display the data entered by the user.

Uploaded by

217y1a66g4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Aim: Java program on Data types.

Program:
import java.util.*;
class Infoo
{
public static void main(String argv[])
{
Scanner Obj = new Scanner(System.in);
System.out.print("Enter name: ");
String name = Obj.nextLine();
System.out.print("Enter Rollno: ");
int rollno = Obj.nextInt();
System.out.print("Enter your age: ");
short age = Obj.nextShort();
System.out.print("Enter Sno: ");
byte sno = Obj.nextByte();
System.out.print("Enter your gender (F/M): ");
char gender = Obj.next().charAt(0);
System.out.print("Enter your ph no : ");
long phno = Obj.nextLong();
System.out.print("Enter your GPA: ");
Float gpa = Obj.nextFloat();
System.out.print("Enter your attendances ");
double attend = Obj.nextDouble();
System.out.print("Do you have back logs true or false ");
boolean backlogs = Obj.nextBoolean();
System.out.println("S.NO: " + sno+"Name: "+name+"\n Roll.no: " +rollno+"\n Age: "+age+"\nGPA:
"+gpa+"\nAttendance: "+attend+"\nGender: "+ gender + "\nPhone no: "+phno + "\nBacklogs: "+backlogs);
}
}
OUTPUT:
C:\Users\MLRITM\Desktop\217Y1A0531>javac Infoo.java
C:\Users\MLRITM\Desktop\217Y1A0531>java Infoo
enter sno
100
enter marks
90
enter phoneno
1234567890
enter accno
234567
enter avg
99
enter attendence
99
enter result
true
enter name
mounika
sno : 100
name :mounika
marks :90
phoneno :1234567890
accno :234567
avg :99.0
attendence :99.0
grade :A
result :true
Aim: Java program to generate the Fibonacci series up to given
value. Program:
import java.io.*;
import java.util.*;
class Fibo1
{
public static void main(String argv[])
{
int a=0,b=1,c=a+b,n;
Scanner obj= new Scanner(System.in);
System.out.print("Enter a value: ");
n=obj.nextInt();
System.out.println("FIbonacci series: ");
System.out.print(a+" "+b);
while(c<=n)
{
System.out.print(" "+c);
a=b;
b=c;
c=a+b;
}
}
}

Output:
Aim: Write a Java program to find factorial of a number

Program:
import java.util.*;
class Fact1
{
public static void main(String argv[])
{
Scanner obj=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=obj.nextInt(),feb=1;
for(int i=1;i<=n;i++)
feb*=i;
System.out.print("Factorial of "+n+" is "+feb);
}
}

Output:
Aim: Write a Java program to check a String is palindrome or not

Program:
import java.io.*;
import java.util.*;
class Palindrome1
{
public static void main(String argv[])
{
String str,reverse="";
Scanner obj=new Scanner(System.in);
System.out.print("Enter a string: ");
str=obj.nextLine();
int len=str.length();
for(int i=len-1;i>=0;i--)
reverse=reverse+str.charAt(i);
if(str.equals(reverse))
System.out.print(str+" is a palindrome");
else
System.out.print(str+" is not a palindrome");
}
}

Output:
Aim: write a Java program to print an array.
Program:
import java.io.*;
class Array
{
public static void main(String argv[])
{
int arr[]={10,20,30,40,50};
System.out.println("Elements of an array: ");
for(int i=0;i<arr.length;i++)
System.out.print(arr[i]+" ");
System.out.println("\nElements of an array using for each: ");
for(int i:arr)
System.out.print(i+" ");

int arr1[]=new int[7];


arr1[0]=30;
arr1[1]=40;
arr1[2]=1000;
arr1[3]=20;
arr1[4]=200;
arr1[5]=100;
arr1[6]=67;
System.out.println("\elements of array:");
for(int i:arr1)
System.out.print(i+" ");

}}

Output:
Aim: Write a Java program to find Quadratic equation.
Program:
import java.util.*;
class Quad
{
public static void main(String arg[])
{
double root1,root2;
Scanner obj = new Scanner(System.in);
System.out.print("Enter a value: ");
int a =obj.nextInt();
System.out.print("Enter b value: ");
int b = obj.nextInt();
System.out.print("Enter c value: ");
int c= obj.nextInt();
int dis=(b*b)-(4*a*c);
if(dis==0)
{
root1=root2=(-b)/(2*a);
System.out.println("Roots are real and equal: \nRoot1: "+root1+"\nRoot2:
"+root2);
}
else if(dis>0)
{
double sq=Math.sqrt(dis);
root1=((-b)-sq)/(2*a);
root2=((-b)+sq)/(2*a);
System.out.print("Roots are real and not equal: \nRoot1: "+root1+"\nRoot2: "+root2);
}
else
{
double usq=Math.sqrt(-(dis));
System.out.print("Roots are Imaginary: \nRoot1: "+(-b/(2*a))+"-
i"+(usq/(2*a))+"\nRoot2: "+(-b/(2*a))+"+i"+(usq/(2*a)));
}}}
OUTPUT:
AIM:
Write a program to print electric bill
PROGRAM:
import java.io.*;
import java.util.*;
class Billpay
{
public static void main(String args[])
{
double billpay=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter customer name");
String name=sc.next();
System.out.println("enter usc");
int usc=sc.nextInt();
System.out.println("enter month");
String month=sc.next();
System.out.println("enter units");
int units=sc.nextInt();
if (units<100)
{
billpay=units*1.20;
}
else if(units>100||units<200)
{
billpay=units*2.20;
}
else if(units>200)
{
billpay=units*3.30;
}
System.out.println("The customer has to pay the bill of" +month +" is"
+billpay);
}
}
Output:
Aim: Java program on Data types.
Program:
class Info
{
public static void main(String argv[])
{
Int sno =101;
String name =”monika";
short marks = 90; int phoneno =1234567891;
Long accno=234566543;
Float avg= 9.8f;
double attendance= 98.0;
Char grade=”A”;
boolean backlogs = true;
System.out.println("S.NO: " + sno+"Name: "+name+"\n Roll.no: " +rollno+"\n
Age: "+age+"\nGPA: "+gpa+"\nAttendance: "+attend+"\nGender: "+ gender +
"\nPhone no: "+phoneno + "\nBacklogs: "+backlogs);
}
}
Output:
Aim: Java program to print range of Data types.
Program:
import java.io.*;
class DatatypeRange
{
public static void main(String argv[])
{
System.out.println("Byte Range: ( "+Byte.MIN_VALUE+" ,
"+Byte.MAX_VALUE+" )\n");
System.out.println("Short Range: ( "+Short.MIN_VALUE+" ,
"+Short.MAX_VALUE+" )\n");
System.out.println("Int Range: ( "+Integer.MIN_VALUE+" ,
"+Integer.MAX_VALUE+" )\n");
System.out.println("Long Range: ( "+Long.MIN_VALUE+" ,
"+Long.MAX_VALUE+" )\n");
System.out.println("Float Range: ( "+Float.MIN_VALUE+" ,
"+Float.MAX_VALUE+" )\n");
System.out.println("Double Range: ( "+Double.MIN_VALUE+" ,
"+Double.MAX_VALUE+" )”);
}
}
OUTPUT:

You might also like