Java Articles

Page 335 of 450

Java program to calculate student grades

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 18K+ Views

The following program accepts average from the user, calculates the grade and prints it.Examplepublic class CalculateStudentGrades {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter average of your marks (less than 100)::");       int average = sc.nextInt();       char grade;       if(average>=80){          grade = 'A';       }else if(average>=60 && average=40 && average

Read More

Java program to find the area of a circle

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 23K+ Views

Area of a circle is the product of the square of its radius, and the value of PI, Therefore, to calculate the area of a rectangleGet the radius of the circle.Calculate the square of the radius.Calculate the product of the value of PI and the value of the square of the radius.Print the result.Exampleimport java.util.Scanner; public class AreaOfCircle {    public static void main(String args[]){       int radius;       double area;       Scanner sc = new Scanner(System.in);       System.out.println("Enter the radius of the circle ::");       radius = sc.nextInt();   ...

Read More

Java program to find the area of a circle

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 23K+ Views

Area of a circle is the product of the square of its radius, and the value of PI, Therefore, to calculate the area of a rectangleGet the radius of the circle.Calculate the square of the radius.Calculate the product of the value of PI and the value of the square of the radius.Print the result.Exampleimport java.util.Scanner; public class AreaOfCircle {    public static void main(String args[]){       int radius;       double area;       Scanner sc = new Scanner(System.in);       System.out.println("Enter the radius of the circle ::");       radius = sc.nextInt();   ...

Read More

What is Http/2 Client in Java 9?

raja
raja
Updated on 13-Mar-2020 585 Views

Http/2 Client API introduced in Java 9. It has more performance improvements over Http/1.1 and also supports server-side push events. This makes the website efficient and faster to browse. Http/2 Client is an incubator module named jdk.incubator.httpclient, which means that all features are still not finalized, and new changes may come in future versions of java. It exports jdk.incubator.http package that contains all public APIs.To use Http/2 Client, we need to use the incubator module, we simply pass the httpclient module into JShell using the "–add-modules" command as belowC:\>jshell -v --add-modules jdk.incubator.httpclient | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help introExamplejshell> import jdk.incubator.http.*; jshell> HttpClient httpClient ...

Read More

Write an example to find whether a given string is palindrome using recursion

Arjun Thakur
Arjun Thakur
Updated on 13-Mar-2020 1K+ Views

Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.Following is an example to find palindrome of a given number using recursive function.Examplepublic class PalindromeRecursion {    public static boolean isPalindrome(String str){       if(str.length() == 0 ||str.length()==1){          return true;       }       if(str.charAt(0) == str.charAt(str.length()-1)){          return isPalindrome(str.substring(1, str.length()-1));       }       return false; ...

Read More

Write an example to find whether a given string is palindrome using recursion

Arjun Thakur
Arjun Thakur
Updated on 13-Mar-2020 1K+ Views

Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.Following is an example to find palindrome of a given number using recursive function.Examplepublic class PalindromeRecursion {    public static boolean isPalindrome(String str){       if(str.length() == 0 ||str.length()==1){          return true;       }       if(str.charAt(0) == str.charAt(str.length()-1)){          return isPalindrome(str.substring(1, str.length()-1));       }       return false; ...

Read More

How to debug JShell in Java 9?

raja
raja
Updated on 13-Mar-2020 483 Views

JShell is a REPL tool that allows snippets of code to be run without placing them in classes. This tool provides a way to evaluate declarations, statements, and expressions in Java and no need to create the main() method to test some parts of the code.The command "/debug" can be used to display debugging information for the JShell tool implementation. Once we type the "/debug" command, the debugging mode is on. After enabling the debug mode and type something like a simple addition, or a simple string, then it prints as below.Example-1jshell> /debug | Debugging on jshell> 5+3 Compiling: 5+3 Kind: EXPRESSION_STATEMENT ...

Read More

How to implement a String in JShell in Java 9?

raja
raja
Updated on 13-Mar-2020 438 Views

JShell is Java’s first official REPL application introduced in Java 9. It is a tool that helps in executing and evaluating simple java programs, and small logics such as statements,  simple programs, loops, expressions, etc. Java REPL can provide a simple programming environment in a command-line prompt. It reads the input, evaluates it, and prints the output.In the below example, we can implement a string with pre-defined methods of String class.Examplejshell> String str = "{abcd}"; str ==> "{abcd}" jshell> str.substring(2, str.length() - 1) $7 ==> "bcd" jshell> String s1 = new String("abcd"); s1 ==> "abcd" jshell> String s2 ...

Read More

What does the method toString(int[] a) do?

karthikeya Boyini
karthikeya Boyini
Updated on 13-Mar-2020 122 Views

The toString(int[]) method of the class java.util.Arrays return a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int[] i1 = new int[] { 33, 12, 98 };       System.out.println("The array is:");       for (int number : i1) {          System.out.println("Number = " + number);   ...

Read More

What does the method fill(obj[], object val) do?

Sharon Christine
Sharon Christine
Updated on 13-Mar-2020 247 Views

The fill(Object[] a, Object val) method of the java.util.Arrays class assigns the specified Object reference to each element of the specified array of Objects.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object arr[] = new Object[] {10.5, 5.6, 4.7, 2.9, 9.7};       System.out.println("Actual values: ");       for (Object value : arr) {          System.out.println("Value = " + value);       }       Arrays.fill(arr, 12.2);       System.out.println("New values after using fill() method: ");       for (Object value : arr) {          System.out.println("Value = " + value);       }    } }OutputActual values: Value = 10.5 Value = 5.6 Value = 4.7 Value = 2.9 Value = 9.7 New values after using fill() method: Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2

Read More
Showing 3341–3350 of 4,496 articles
« Prev 1 333 334 335 336 337 450 Next »
Advertisements