NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

PROGRAM: 8
AIM: (a) WAP to take input from user(0-9) if user enters odd number print digitalised output if not print invalid.
(b) WAP to implement final keyword in classes, function and variables.
SOURCE CODE:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int n=sc.nextInt();
switch(n)
{
case 0:
case 2:
case 4:
case 6:
case 8:
System.out.println("INVALID!");
break;
case 1:
System.out.println("|n|");
break;
case 3:
System.out.println("_n_|n_|");
break;
case 5:
System.out.println(" _n|_n _|");
break;
case 7:
System.out.println("_ _n |n |");
break;
case 9:
System.out.println(" _n|_|n _|");
}
}
}
OUPUT:

(b)
SOURCE CODE:
package neha;
final class Main1
{
final void print()
{
System.out.println("THIS IS FINAL CLASS");
}
}
class Main extends Main1{
void print()
{
System.out.println("'THE FINAL METHOD'");
}
public static void main(String[] args)
{
Main obj=new Main();
obj.print();
Main1 obj1=new Main1();
obj1.print();
System.out.println(" 'THE FINAL VARIABLE' ");
final int a[]={1,2,3};
for(int i=0;i<3;i++)
{
System.out.println(a[i]);
}
}
}
OUTPUT:










Date: 18th October,2019
PROGRAM: 9
AIM: Write a program to read from a file and write to a file.
SOURCE CODE:
import java.io.*;
public class Test {
public static void main(String [] args) {
String fileName = "temp.txt";
String line = null;

try {
FileReader fileReader =
new FileReader(fileName);
BufferedReader bufferedReader =
new BufferedReader(fileReader);

while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}
}
OUTPUT:






DATE: 25th October,2019
PROGRAM: 10
AIM: Write a program using JDBC to insert, create, delete and update a table.
SOURCE CODE:
import java.sql.*;
class EmployeeRecord
{
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:XE";
public static final String DBUSER = "local";
public static final String DBPASS = "test";
public static void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
String sql = "INSERT INTO emp (emp_id, empname, email, city) VALUES (?, ?, ?, ?)";
PreparedStatement statement = con.prepareStatement(sql);
statement.setInt(1, 100);
statement.setString(2, "Prashant");
statement.setString(3, "[email protected]");
statement.setString(4, "Pune");

int rowsInserted = statement.executeUpdate();
if (rowsInserted > 0)
{
System.out.println("A new employee was inserted successfully!n");
}
String sql1 = "SELECT * FROM Emp";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(sql1);

while (result.next())
{
System.out.println (result.getInt(1)+" "+
result.getString(2)+" "+
result.getString(3)+" "+
result.getString(4));
}
String sql2 = "Update Emp set email = ? where empname = ?";
PreparedStatement pstmt = con.prepareStatement(sql2);
pstmt.setString(1, "[email protected]");
pstmt.setString(2, "Jaya");
int rowUpdate = pstmt.executeUpdate();
if (rowUpdate > 0)
{
System.out.println("nRecord updated successfully!!n");
}
String sql3 = "DELETE FROM Emp WHERE empname=?";
PreparedStatement statement1 = con.prepareStatement(sql3);
statement1.setString(1, "Prashant");

int rowsDeleted = statement1.executeUpdate();
if (rowsDeleted > 0)
{
System.out.println("A Employee was deleted successfully!n");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.