0% found this document useful (0 votes)
50 views4 pages

Java Basics Lab Practice

The document contains 8 code snippets that demonstrate various Java concepts like data types, input/output, type casting, and calculations. The code snippets include: 1. A method to display event details by passing parameters 2. Displaying ASCII value of a character input 3. Adding integers from an array using type casting 4. Calculating area of a tile game board by multiplying sides 5. Converting Celsius to Fahrenheit 6. Demonstrating different data types by taking input 7. Calculating number of days for different stages of a trade fair 8. No code shown, described as displaying student details
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Java Basics Lab Practice

The document contains 8 code snippets that demonstrate various Java concepts like data types, input/output, type casting, and calculations. The code snippets include: 1. A method to display event details by passing parameters 2. Displaying ASCII value of a character input 3. Adding integers from an array using type casting 4. Calculating area of a tile game board by multiplying sides 5. Converting Celsius to Fahrenheit 6. Demonstrating different data types by taking input 7. Calculating number of days for different stages of a trade fair 8. No code shown, described as displaying student details
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

-----------------------------------------------------------------------------------

-------------------------------------1
import [Link];
class Main
{
static void display(String event,String type,int count,char paid,float expense)
{
[Link]("Event Name : "+event);
[Link]("Event Type : "+type);
[Link]("Expected Count : "+count);
[Link]("Paid Entry: "+paid);
[Link]("Projected Expense: "+expense+"L");
}
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
String event=[Link]();
String type=[Link]();
int count=[Link]();
char paid=[Link]().charAt(0);
float expense=[Link]();
display(event,type,count,paid,expense);
}
}

olp:-
track 1
public
500
Y
56.0

Event Name : track 1


Event Type : public
Expected Count : 500
Paid Entry: Y
Projected Expense: 56.0L

-----------------------------------------------------------------------------------
-------------------------------2(display asci value in character)

import [Link];
class Main
{
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
char input=[Link]().charAt(0);
int value1=input;
if (value1>=65 && value1<=122)
{
float value2=input;
[Link]("int:"+value1);
[Link]("float:"+value2);
[Link]("byte:"+value1);
[Link]("short:"+value1);
}
else
{
[Link]("Invalid");
}
}
}

olp:-

int:65
float:65.0
byte:65
short:65

-----------------------------------------------------------------------------------
----------------3(play with type casting)

import [Link];
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
int nums[];
nums = new int[2];
int i,temp=0;

for (i = 0; i < [Link]; i++) {


nums[i] = [Link]();
}
for (i = 0; i < [Link]; i++) {
temp=temp+nums[i];
}
double total=temp;
[Link](total);
}
}

olp:-

10 2
12
-----------------------------------------------------------------------------------
--------------------4(tile game)(2 test cases passed) change the approach
import [Link];
class Main
{
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
int side=[Link]();
int no_tiles=[Link]();
side=side+side;
int large_tile=side*side;
[Link](large_tile);
}
}

olp:-
5
8
100
-----------------------------------------------------------------------------------
-----5)celsius to fahreheit

import [Link];
class Main
{
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
int celsius=[Link]();
double fahrenheit=(1.8*(celsius))+32;
[Link](fahrenheit);
}
}

olp:-

51
123.8
---------------------------------------------------------------------------------
6)basic different data types$$$$(this question it is running in vscode but not in
neocode platform)
import [Link];
class Main
{
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
int a=[Link]();
double b=[Link]();
boolean c=[Link]();
char d=[Link]().charAt(0);
Scanner obj1=new Scanner([Link]);
String f=[Link]();
[Link]("Integer value = "+a);
[Link]("Double value = "+b);
[Link]("Boolean value = "+c);
[Link]("char value = "+d);
[Link]("String value = "+f);
}
}

olp:-

1
1.21
true
g
this ios dawsd wdwa
Integer value = 1
Double value = 1.21
Boolean value = true
char value = g
String value = this ios dawsd wdwa
-----------------------------------------------------------------------------------
-------7)Trade fair

import [Link];
class Main
{
public static void main(String[] args)
{
Scanner obj=new Scanner([Link]);
int a=[Link]();
int day1=(a*2)/7;
int day2=(day1*2);
int day3=(day1)/2;
[Link](day1);
[Link](day2);
[Link](day3);
}
}
olp:-
10500

3000
6000
1500
-----------------------------------------------------------------------------------
----------------8)display student's detail
rest are basic.

You might also like