❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Logical program -1 -> read the number from standard input using scanner and another without scanner class

By: Prasanth
5 June 2025 at 11:11

Program-1:

package logicProgramme;

import java.util.Scanner;

public class Scanner_Class_ReadIntegerValue {


// read the number from standard input 

    public static void main(String[] args) {
        int num;
        // print the message to ask the user to enter number
        System.out.println("Enter the integer: ");

        // Scanner class import from utility package.
        //create Scanner object. 
        Scanner  s = new Scanner(System.in);
        //create scanner object s ,to take input from keyboard (System.in)

        //read the input form the user and store it  in num.
        num = s.nextInt();

        System.out.println("Entered interger is: "+ num);

        // closes the scanner to free up the resourse.
        s.close();


    }

}

Program-2

package logicProgramme;

public class ReadInetegerWithoutScanner {


    // read the number from  without scanner class


    public static void main(String[] args) {
    if (args.length >0) // check the  user entered input or no.
    {
        int num =Integer.parseInt(args[0]);
        // Integer.parseInt(args[0]); , Integer.parseInt -> it is convert  string to integer, args[0] , index of  array 0 the postion take the input 
        // parse mean read and  convert , int means integer - string to int convert 
        // example:-i entered arg tab 123 and it String args output 45  
        // in eclipse right click file -> runs as -> run configuration -> argument tab  give nput and apply and run.

        // simple Integer ,java class  in java.lang package parseInt
        //Integer -> class ,  parseInt method,

        System.out.println("Entered integer is: "+num);
    }
    else
    {
        System.out.println("No integer entered");
    }
    }

}

/*int to String convert 
 * String.valueof();
 * 
 * 
 * /
 */

Example:3-

package logicProgramme;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class UsingBufferedReaderClass {
// how to use BufferReader to read a line of input from the user and print it to the console.
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String input  =reader.readLine();

        System.out.println(input);


    }

}
/*
 * 1.Bufferedreader -> Bufferedreader in java class read the text from the charater(not byte )  input stream. 
 * 
 * system.in read the byte from the keyboard  not characters.(system.in  can not directely  read string or line -only raw bytes)
 * 
 *2.InputStreamReader -> it is a bridge b/w System.in (bytes)  and java character
 * it is convert to  byte to character, so help full for  read text from keyboard.
 * 
 * 3.readline() it method  of Bufferereader, it ead one full line of text and it is return a string 
 */

/*BufferedReader it  java class read the text chracter not bytes, system.in  , 
 * it read  input from keyboard like byte not a character, Inputstreamreader is it help convert byte to character ,and read text in keyboard and , it bridge b/w  (system.in)  byte and character, and readLine() methdod of  Bufferereader class,it reade the  text line
 * 
 * 
 */

Task – SSLC Marks Total

By: Sugirtha
29 September 2024 at 12:22
<html>
    <head>
        <title> SSLC Marks </title>
        <style>
            body 
            {
                background-color:black;
                color:pink;
                font-family:arial;
            }
            h1 
            {
            text-align:center;
            color:pink;
            font-variant:small-caps;
            }

            th {
                background-color:pink;
                color:black;
                font-size: 20px;
                font-variant:small-caps;
               }
           .inputTxt{
                color:black;
                background-color:lightgrey;
                border:green 2px solid;
                padding-left:10px;
                width:170px;
                height:30px;
                font-size:20px;
                font-family:"Arial";
                }
            .lbl {
                 padding:25px;
                 font-weight:bold;
                   
                }
            
            .button {
                background-color:lightgrey;
                color: black;
                border:2px solid pink;
                border-radius:15px;
                font-size: 15px;
                vertical-align:9px;
                font-family:"sans-serief";
                font-variant:small-caps;
                font-weight:bold;
                width:170px;
                height:30px;
                text-align:center;
            }
            .output {
                font-family:"Arial";
                font-size:20px;
                font-weight:bold;
                padding-left:25px;
            }


            
        </style>
    </head>
    
    <body>
        <h1> SSLC Marks </h1>
        <table border="1" align=center>
            <thead>
                <th>Subjects</th> <th>Marks</th> 
            </thead>
            <tbody>
            <form id="frmMarks">
            <tr> 
                <td > <label for = "idTamil" class="lbl"> Tamil</label> </td>
                <td> <input type="text" name="txtTamil" id="idTamil" class="inputTxt">  </td>
            </tr>
            <tr> 
                <td> <label for = "idEng"  class="lbl"> English</label> </td>
                <td> <input type="text" name="txtEng" id="idEng" class="inputTxt"> </td>
            </tr>
            <tr> 
                <td> <label for = "idMath" class="lbl"> Maths</label> </td>
                <td> <input type="text" name="txtMath" id="idMath" class="inputTxt"> </td>
            </tr>
            <tr> 
                <td> <label for = "idSci"  class="lbl"> Science</label> </td>
                <td> <input type="text" name="txtSci" id="idSci" class="inputTxt"> </td>
            </tr>
            <tr> 
                <td> <label for = "idSS"  class="lbl"> Social Science</label> </td>
                <td> <input type="text" name="txtSS" id="idSS" class="inputTxt"> </td>
            </tr>
            <tr><td></td></tr<tr><td></td></tr>
             <tr> 
                <td> <label for = "idTot" class="output">Total Marks</label> </td>
                <td align="center"><output name="totMarks" id="idTot" class="output" form="frmMarks"></output</td>
            </tr>  
             <tr> 
                <td > <label for = "idPercent" class="output">Percentage %</label> </td>
                <td align="center"><output name="percent" id="idPercent" class="output" form="frmMarks"></output</td>
            </tr>  
        </tbody>
        </table>
        <br><br>
        <div align="center">
            <input type="button" value="CLEAR" class="button" onclick="doClear()"> &nbsp;&nbsp;&nbsp;
            <input type="button" value="CALC TOTAL & %"  class="button" onclick="calcTot()">
        </div>
        </form>

    </body>
    
    <script>
        function calcTot() {
            const tot = parseInt(document.querySelector("#idTamil").value) + parseInt(document.querySelector("#idEng").value) + parseInt(document.querySelector("#idMath").value) + parseInt(document.querySelector("#idSci").value) + parseInt(document.querySelector("#idSS").value);
            document.querySelector("#idTot").innerHTML = tot;
            alert(tot/5);
            document.getElementById("idPercent").innerHTML = Math.round((tot/5)*100)/100+"%";
        }
        function doClear() {
            document.querySelector("#frmMarks").reset();
            document.querySelector("#idTot").innerHTML="";    
            document.getElementById("idPercent").innerHTML="";       
        }
    </script>
</hmtl>

Output:

❌
❌