Sample java programs for beginners. This slides can help you to print few words in java. Also it helps to do arithmetic calculations and will give you basic concept of for loop, do while loop and if else statements in java. Area of a square.
The document discusses Java's Math and Random classes. It provides examples of how to use common Math class methods like pow(), abs(), ceil(), floor(), max(), min(), and sqrt() to calculate powers, absolute values, rounding, maximum/minimum values, and square roots of numbers. It also shows how to generate random numbers between 0-5 using the Random class's nextInt() method.
This document contains the Java code for an insertion sort algorithm. It defines a main method that takes in user input of 5 integer values, stores them in an array, and then sorts the array using insertion sort. It iterates through the array, compares adjacent elements, and swaps them if out of order until the array is fully sorted from lowest to highest value. The sorted array is then printed out at the end.
The document describes a Java program to calculate parcel shipping charges based on weight. It begins with an initial charge of Rs. 15 for the first 1KG. Any additional weight is charged Rs. 8 for every 500g or fraction thereof. The program takes a weight in KGs as input, calculates the remaining weight after deducting 1KG, determines the charge for full 500g increments and any fractional part, and outputs the total charge.
Deletion of an element at a given particular positionKavya Shree
This presentation gives you basic knowledge on arrays, how to define ,access,deleting an particular element present in the array and if the element is not present then print element not found
The document discusses C#.NET programs and various simple console applications that demonstrate basic programming concepts like input/output, conditional statements, loops, arrays, and pattern printing. It includes 10 programs that perform tasks like calculating sums, swapping values, checking odd/even, and more. It also covers 4 programs using different looping structures and 5 programs that print numeric patterns using nested loops.
Prerna Sharma, a B.Tech student, conducted an experiment using MATLAB to draw the waveforms of log(x) and log(x^2). She created code that defined x and y variables, took the log of x and x^2, plotted the results, and added a grid. The waveforms were successfully drawn.
This document contains code written by Ankit Gupta for an assignment. It includes 6 Java programs: 1) A program to calculate the sum of first n numbers using a for loop. 2) A program to find the maximum of n numbers using a do-while loop. 3) A program to find all Armstrong numbers between 0 and 999. 4) A program to correct common typing errors. 5) A program to solve a problem related to the gangster Dawood Abrahim. 6) Additional Java programs and problems solved by Ankit Gupta.
The document discusses Java's Math and Random classes. It provides examples of how to use common Math class methods like pow(), abs(), ceil(), floor(), max(), min(), and sqrt() to calculate powers, absolute values, rounding, maximum/minimum values, and square roots of numbers. It also shows how to generate random numbers between 0-5 using the Random class's nextInt() method.
This document contains the Java code for an insertion sort algorithm. It defines a main method that takes in user input of 5 integer values, stores them in an array, and then sorts the array using insertion sort. It iterates through the array, compares adjacent elements, and swaps them if out of order until the array is fully sorted from lowest to highest value. The sorted array is then printed out at the end.
The document describes a Java program to calculate parcel shipping charges based on weight. It begins with an initial charge of Rs. 15 for the first 1KG. Any additional weight is charged Rs. 8 for every 500g or fraction thereof. The program takes a weight in KGs as input, calculates the remaining weight after deducting 1KG, determines the charge for full 500g increments and any fractional part, and outputs the total charge.
Deletion of an element at a given particular positionKavya Shree
This presentation gives you basic knowledge on arrays, how to define ,access,deleting an particular element present in the array and if the element is not present then print element not found
The document discusses C#.NET programs and various simple console applications that demonstrate basic programming concepts like input/output, conditional statements, loops, arrays, and pattern printing. It includes 10 programs that perform tasks like calculating sums, swapping values, checking odd/even, and more. It also covers 4 programs using different looping structures and 5 programs that print numeric patterns using nested loops.
Prerna Sharma, a B.Tech student, conducted an experiment using MATLAB to draw the waveforms of log(x) and log(x^2). She created code that defined x and y variables, took the log of x and x^2, plotted the results, and added a grid. The waveforms were successfully drawn.
This document contains code written by Ankit Gupta for an assignment. It includes 6 Java programs: 1) A program to calculate the sum of first n numbers using a for loop. 2) A program to find the maximum of n numbers using a do-while loop. 3) A program to find all Armstrong numbers between 0 and 999. 4) A program to correct common typing errors. 5) A program to solve a problem related to the gangster Dawood Abrahim. 6) Additional Java programs and problems solved by Ankit Gupta.
The document defines classes for an Employee, Officer, and Manager. The Employee class stores employee details like name, address, phone number, age, and salary. The Officer and Manager classes extend the Employee class and add additional fields for specialization and department respectively. The main method creates objects of Officer and Manager, reads their details, and displays the output. It also overrides the salary calculation for Engineer class.
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
This document provides examples of C++ functions for 2D arrays:
1. A function to display the middle row and column of a 2D array.
2. A function to swap the first and last columns of a 2D array.
3. A function to calculate the sum of each row in a 2D array.
4. A function to calculate the product of each column in a 2D array.
5. A function to print elements of a 2D array whose units place is 3.
Practice questions are also provided to write additional functions for 2D arrays.
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
This document provides information and examples on how to write functions to manipulate 2D arrays in C++ for computer science exams. It discusses 2D array function headers, passing 2D arrays as arguments, and examples of functions to print, calculate sums, and manipulate elements of 2D arrays, such as printing diagonals, triangles, and alternate elements. It concludes with practice questions on writing functions to calculate sums of upper, lower and alternate elements of a 2D array.
iGraph is an open source Python module for network analysis. It allows importing graphs into Python and generating graphs using built-in deterministic and stochastic graph generators. Key functions include adding/removing vertices and edges, calculating graph properties like degrees and betweenness centrality, and comparing graphs for isomorphism.
This document provides instructions for an assignment on Java programming II. It includes 4 questions - the first asks to write code for a linear search on a sample array and identify the index position of a target number. The second calculates time complexity for linear search and merge sort. The third asks to convert an iterative factorial method to a recursive one. The fourth provides an unsorted array and asks to sort it using selection sort and display the output.
Frequency count of the Element in an arrayKavya Shree
This presentation gives you a very depth knowledge on algorithm and how to write the logic for a given problem and how to write a procedural program using C++ language
This Java program encrypts strings by shifting letters 3 positions forward in the alphabet, wrapping around from z to c, and preserving spaces and other characters. The user inputs a string which is encrypted by shifting each character and storing it in a new array before outputting the encrypted string.
An experiment was conducted in MATLAB to generate an exponential signal. The program prompts the user to enter the length of the sequence and the value of a. It then generates the exponential sequence y=exp(a*t) from t=0 to the input length and plots it as a stem plot with amplitude and n labels. When run with a length of 7 and a value of 1, it successfully generated the exponential signal as observed in the plot. Precautions include carefully typing the program and observing the output signal.
An experiment was conducted in MATLAB to generate an exponential signal. The program prompts the user to enter the length of the sequence and the value of a. It then calculates the exponential function exp(a*t) for t from 0 to the input length and plots the resulting signal. The experiment was run with a sequence length of 7 and a value of 1, successfully generating the exponential signal as observed in the plot.
This document discusses one and two dimensional arrays in Visual Basic. It includes examples of declaring and initializing one and two dimensional arrays, using nested loops to iterate through elements in two dimensional arrays, and self-test questions involving manipulating elements in arrays and matrices using loops. Examples are provided for initializing arrays to zero, filling arrays with values, accessing row and column lengths, summing elements in rows and matrices, and copying/separating arrays.
This program takes an integer as input from the user, squares that number using a*a, and outputs the squared value. The program demonstrates how to calculate the square of an integer number entered by the user through a simple C++ program that multiples the input value by itself and displays the result.
An overview of the most simple algorithms used in data structures for path finding. Dijkstra, Breadth First Search, Depth First Search, Best First Search and A-star
Naturally feel free to copy for assignments and all
This document contains an assignment submission for a programming fundamentals course. It includes 8 sections with 2 code examples each demonstrating different programming concepts like printing text, if/else statements, loops, functions, and arrays in C programming language. The codes show basics like finding the sum of two numbers, checking even/odd, generating patterns, finding repeated elements in an array. The assignment was submitted by Zohaib Zeeshan to their professor for the first semester course.
Describes Map data structure, its methods and implementation using Hash tables & linked list along with their running time. Hash table components, bucket Array and hash function. Collision handing strategies: Separate chaining, Linear probing, quadratic probing, double hashing.
Ordered Maps and corresponding binary search
The document contains instructions and source code for exercises in a Fundamental Programming 1 session. It includes exercises to print patterns using output statements, print name and details, fix errors in a program, take input and perform calculations, and calculate volume, area, and odd/even numbers. Students are asked to write C programs to demonstrate input/output statements, taking user input, performing calculations, and applying conditional logic. Their work will be assessed based on specifications, readability, errors, concept understanding, and delivery.
The Ring programming language version 1.6 book - Part 49 of 189Mahmoud Samir Fayed
This document discusses using the RingLibSDL library in Ring to create games. It provides examples of creating a window, displaying an image, playing sounds, using fonts, and handling input. Functions covered include SDL_Init(), SDL_CreateWindow(), SDL_LoadBMP(), SDL_CreateTextureFromSurface(), SDL_RenderCopy(), SDL_Delay(), and SDL_Quit().
x = 2 and z = 4. y is calculated using various operations on x and z:
1) y = x++ + ++x evaluates to 6 as x is incremented twice.
2) y = ++x + ++x evaluates to 8 as both x values are pre-incremented.
3) y = ++x + ++x + ++x evaluates to 13 as x is incremented three times.
4) y = x > z evaluates to 0 as the relation x > z is false.
5) y = x > z ? x : z evaluates to 4 as z is chosen by the conditional operator.
6) y = x & z evaluates to 0 as the bitwise
The document discusses how to pass arguments to the main function in C programs. Arguments passed on the command line when running a program can be accessed in main through two parameters: argc contains the number of arguments, and argv is a string array containing the argument values. A sample C program is given that prints the program name and each argument value using argc and argv to loop through and access the arguments.
The document contains code to add two matrices of given size. It takes the number of rows and columns as input to create two matrices of that size. It then takes elements of both matrices as input and stores them. It iterates through both matrices to add the elements and stores the result in a third sum matrix. Finally, it prints the sum matrix.
The document contains code for several Java programs. The first program takes a number input and checks if it is evenly divisible by 9. The second program calculates the areas of different shapes like rectangle, circle and triangle by taking length, width, radius or base and height as user input. The third program is a menu to order drinks from a pub by selecting different drinks and entering the quantity. It calculates and displays the total cost. The last program calculates distance traveled by taking speed and time as input.
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45
Solution
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45.
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
MagicSquareTest.java
import java.util.Scanner;
public class MagicSquareTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter Number of rows:\");
int rows = scan.nextInt();
System.out.println(\"Enter Nummber of columns:\");
int cols = scan.nextInt();
int a[][] = new int[rows][cols];
System.out.println(\"Enter matrix elements;\");
for(int i=0; i
Solution
MagicSquareTest.java
import java.util.Scanner;
public class MagicSquareTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter Number of rows:\");
int rows = scan.nextInt();
System.out.println(\"Enter Nummber of columns:\");
int cols = scan.nextInt();
int a[][] = new int[rows][cols];
System.out.println(\"Enter matrix elements;\");
for(int i=0; i.
The document defines classes for an Employee, Officer, and Manager. The Employee class stores employee details like name, address, phone number, age, and salary. The Officer and Manager classes extend the Employee class and add additional fields for specialization and department respectively. The main method creates objects of Officer and Manager, reads their details, and displays the output. It also overrides the salary calculation for Engineer class.
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
This document provides examples of C++ functions for 2D arrays:
1. A function to display the middle row and column of a 2D array.
2. A function to swap the first and last columns of a 2D array.
3. A function to calculate the sum of each row in a 2D array.
4. A function to calculate the product of each column in a 2D array.
5. A function to print elements of a 2D array whose units place is 3.
Practice questions are also provided to write additional functions for 2D arrays.
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
This document provides information and examples on how to write functions to manipulate 2D arrays in C++ for computer science exams. It discusses 2D array function headers, passing 2D arrays as arguments, and examples of functions to print, calculate sums, and manipulate elements of 2D arrays, such as printing diagonals, triangles, and alternate elements. It concludes with practice questions on writing functions to calculate sums of upper, lower and alternate elements of a 2D array.
iGraph is an open source Python module for network analysis. It allows importing graphs into Python and generating graphs using built-in deterministic and stochastic graph generators. Key functions include adding/removing vertices and edges, calculating graph properties like degrees and betweenness centrality, and comparing graphs for isomorphism.
This document provides instructions for an assignment on Java programming II. It includes 4 questions - the first asks to write code for a linear search on a sample array and identify the index position of a target number. The second calculates time complexity for linear search and merge sort. The third asks to convert an iterative factorial method to a recursive one. The fourth provides an unsorted array and asks to sort it using selection sort and display the output.
Frequency count of the Element in an arrayKavya Shree
This presentation gives you a very depth knowledge on algorithm and how to write the logic for a given problem and how to write a procedural program using C++ language
This Java program encrypts strings by shifting letters 3 positions forward in the alphabet, wrapping around from z to c, and preserving spaces and other characters. The user inputs a string which is encrypted by shifting each character and storing it in a new array before outputting the encrypted string.
An experiment was conducted in MATLAB to generate an exponential signal. The program prompts the user to enter the length of the sequence and the value of a. It then generates the exponential sequence y=exp(a*t) from t=0 to the input length and plots it as a stem plot with amplitude and n labels. When run with a length of 7 and a value of 1, it successfully generated the exponential signal as observed in the plot. Precautions include carefully typing the program and observing the output signal.
An experiment was conducted in MATLAB to generate an exponential signal. The program prompts the user to enter the length of the sequence and the value of a. It then calculates the exponential function exp(a*t) for t from 0 to the input length and plots the resulting signal. The experiment was run with a sequence length of 7 and a value of 1, successfully generating the exponential signal as observed in the plot.
This document discusses one and two dimensional arrays in Visual Basic. It includes examples of declaring and initializing one and two dimensional arrays, using nested loops to iterate through elements in two dimensional arrays, and self-test questions involving manipulating elements in arrays and matrices using loops. Examples are provided for initializing arrays to zero, filling arrays with values, accessing row and column lengths, summing elements in rows and matrices, and copying/separating arrays.
This program takes an integer as input from the user, squares that number using a*a, and outputs the squared value. The program demonstrates how to calculate the square of an integer number entered by the user through a simple C++ program that multiples the input value by itself and displays the result.
An overview of the most simple algorithms used in data structures for path finding. Dijkstra, Breadth First Search, Depth First Search, Best First Search and A-star
Naturally feel free to copy for assignments and all
This document contains an assignment submission for a programming fundamentals course. It includes 8 sections with 2 code examples each demonstrating different programming concepts like printing text, if/else statements, loops, functions, and arrays in C programming language. The codes show basics like finding the sum of two numbers, checking even/odd, generating patterns, finding repeated elements in an array. The assignment was submitted by Zohaib Zeeshan to their professor for the first semester course.
Describes Map data structure, its methods and implementation using Hash tables & linked list along with their running time. Hash table components, bucket Array and hash function. Collision handing strategies: Separate chaining, Linear probing, quadratic probing, double hashing.
Ordered Maps and corresponding binary search
The document contains instructions and source code for exercises in a Fundamental Programming 1 session. It includes exercises to print patterns using output statements, print name and details, fix errors in a program, take input and perform calculations, and calculate volume, area, and odd/even numbers. Students are asked to write C programs to demonstrate input/output statements, taking user input, performing calculations, and applying conditional logic. Their work will be assessed based on specifications, readability, errors, concept understanding, and delivery.
The Ring programming language version 1.6 book - Part 49 of 189Mahmoud Samir Fayed
This document discusses using the RingLibSDL library in Ring to create games. It provides examples of creating a window, displaying an image, playing sounds, using fonts, and handling input. Functions covered include SDL_Init(), SDL_CreateWindow(), SDL_LoadBMP(), SDL_CreateTextureFromSurface(), SDL_RenderCopy(), SDL_Delay(), and SDL_Quit().
x = 2 and z = 4. y is calculated using various operations on x and z:
1) y = x++ + ++x evaluates to 6 as x is incremented twice.
2) y = ++x + ++x evaluates to 8 as both x values are pre-incremented.
3) y = ++x + ++x + ++x evaluates to 13 as x is incremented three times.
4) y = x > z evaluates to 0 as the relation x > z is false.
5) y = x > z ? x : z evaluates to 4 as z is chosen by the conditional operator.
6) y = x & z evaluates to 0 as the bitwise
The document discusses how to pass arguments to the main function in C programs. Arguments passed on the command line when running a program can be accessed in main through two parameters: argc contains the number of arguments, and argv is a string array containing the argument values. A sample C program is given that prints the program name and each argument value using argc and argv to loop through and access the arguments.
The document contains code to add two matrices of given size. It takes the number of rows and columns as input to create two matrices of that size. It then takes elements of both matrices as input and stores them. It iterates through both matrices to add the elements and stores the result in a third sum matrix. Finally, it prints the sum matrix.
The document contains code for several Java programs. The first program takes a number input and checks if it is evenly divisible by 9. The second program calculates the areas of different shapes like rectangle, circle and triangle by taking length, width, radius or base and height as user input. The third program is a menu to order drinks from a pub by selecting different drinks and entering the quantity. It calculates and displays the total cost. The last program calculates distance traveled by taking speed and time as input.
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45
Solution
SumNumbers.java
import java.util.Scanner;
public class SumNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int sum = 0;
while(true){
System.out.println(\"Enter integer:\");
int n = scan.nextInt();
if(n == -1){
break;
}
sum = sum + n;
}
System.out.println(\"The sum is \"+sum);
}
}
Output:
Enter integer:
1
Enter integer:
2
Enter integer:
3
Enter integer:
4
Enter integer:
5
Enter integer:
6
Enter integer:
7
Enter integer:
8
Enter integer:
9
Enter integer:
-1
The sum is 45.
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
MagicSquareTest.java
import java.util.Scanner;
public class MagicSquareTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter Number of rows:\");
int rows = scan.nextInt();
System.out.println(\"Enter Nummber of columns:\");
int cols = scan.nextInt();
int a[][] = new int[rows][cols];
System.out.println(\"Enter matrix elements;\");
for(int i=0; i
Solution
MagicSquareTest.java
import java.util.Scanner;
public class MagicSquareTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter Number of rows:\");
int rows = scan.nextInt();
System.out.println(\"Enter Nummber of columns:\");
int cols = scan.nextInt();
int a[][] = new int[rows][cols];
System.out.println(\"Enter matrix elements;\");
for(int i=0; i.
The document contains instructions for 14 programming exercises involving basic Java concepts like user input, arithmetic operations, loops, strings, and prime number identification. The exercises cover printing greetings, calculating triangle areas, generating even numbers, Fibonacci sequences, factorials, and determining parity, in addition to other foundational programming tasks. Students are guided to write Java code to prompt for input, perform calculations, and output results for each problem.
The document contains 12 code examples for Java programs that perform various tasks like greeting a user, calculating triangle area, printing even numbers, generating Fibonacci sequences, calculating factorials, determining if a number is even/odd, comparing two numbers, determining if a number is positive/negative, generating a multiplication table, and reversing a string. Each code example demonstrates the use of basic Java concepts like variables, conditionals, loops, methods, and classes to solve common programming problems.
The document contains 17 code snippets that demonstrate various Java programming concepts like loops, arrays, methods, classes, input/output, etc. Specifically, the code snippets show:
1. Using for loops to print numeric series
2. Accepting user input of different data types using Scanner and parsing
3. Using StringTokenizer and Scanner classes
4. Finding largest number among 3 inputs and printing tables
5. Demonstrating 2D arrays, array of objects, and command line arguments
6. Various String class methods like length(), substring(), indexOf() etc.
The document contains 21 programming problems involving Java concepts like arrays, loops, methods, classes, objects, constructors, and more. For each problem, source code is provided to demonstrate how to solve the problem, followed by sample output. Some key problems include: (1) printing series using nested loops, (2) receiving user input of different data types, (3) using StringTokenizer and Scanner classes, (4) finding largest of 3 numbers, (5) using 2D arrays and array of objects.
The document contains 10 Java programs to solve common mathematical and logical problems:
1) A program to calculate the factorial of a number.
2) A program to add two matrices.
3) A program to calculate the sum of two numbers.
4) A program to reverse a number.
5) A program to check if a number is an Armstrong number.
6) A program to find the largest of three numbers.
7) A program to output the current date and time.
8) A program to check if a string is a palindrome.
9) A program to print prime numbers up to a given limit.
10) A program to swap two numbers.
CODEimport java.util.; public class test { public static voi.pdfanurag1231
CODE:
import java.util.*;
public class test {
public static void main(String args[]) {
int num, sum=0;
Scanner input=new Scanner(System.in);
System.out.print(\"Input num : \");
num=input.nextInt();
while(num != 13) {
sum=sum+num;
System.out.print(\"Input num : \");
num=input.nextInt();
}
sum=sum+num;
System.out.println(\"Sum = \"+sum);
}
}
save the above file as test.java
Output:
javac test.java
java test
Input num :
1
Input num :
2
Input num :
3
Input num :
4
Input num :
5
Input num :
6
Input num :
7
Input num :
8
Input num :
9
Input num :
0
Input num :
13
Sum = 58
Solution
CODE:
import java.util.*;
public class test {
public static void main(String args[]) {
int num, sum=0;
Scanner input=new Scanner(System.in);
System.out.print(\"Input num : \");
num=input.nextInt();
while(num != 13) {
sum=sum+num;
System.out.print(\"Input num : \");
num=input.nextInt();
}
sum=sum+num;
System.out.println(\"Sum = \"+sum);
}
}
save the above file as test.java
Output:
javac test.java
java test
Input num :
1
Input num :
2
Input num :
3
Input num :
4
Input num :
5
Input num :
6
Input num :
7
Input num :
8
Input num :
9
Input num :
0
Input num :
13
Sum = 58.
This document contains 6 Java programs that demonstrate basic programming concepts like input/output, conditionals, loops, and functions. Program 1 takes input from the user and prints the sum. Program 2 prints numbers in a range. Program 3 finds the largest of 3 numbers. Program 4 checks if a number is prime. Program 5 prints the Fibonacci series up to 10 terms. Each program shows the code and expected output.
This document discusses Java input and output. It explains that System.out.println(), System.out.print(), and System.out.printf() can be used for output. println() prints the string and moves to the next line, print() prints the string, and printf() provides string formatting. The Scanner class is used for input, by creating a Scanner object and calling methods like nextInt() and nextDouble(). Examples demonstrate getting integer, float, double, and string input from the user.
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfpremsrivastva8
CountStringCharacters.java
import java.util.Scanner;
public class CountStringCharacters {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter a sentence or phrase: \");
String s = scan.nextLine();
int numOfCharacters = getNumOfCharacters(s);
System.out.println(\"You entered: \"+s);
System.out.println(\"Number of characters: \"+numOfCharacters);
outputWithoutWhitespace(s);
}
public static int getNumOfCharacters(String s){
int numOfCharCount = 0;
for(int i=0; i
Solution
CountStringCharacters.java
import java.util.Scanner;
public class CountStringCharacters {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter a sentence or phrase: \");
String s = scan.nextLine();
int numOfCharacters = getNumOfCharacters(s);
System.out.println(\"You entered: \"+s);
System.out.println(\"Number of characters: \"+numOfCharacters);
outputWithoutWhitespace(s);
}
public static int getNumOfCharacters(String s){
int numOfCharCount = 0;
for(int i=0; i.
import java.util.;public class Program{public static void.pdfoptokunal1
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println(x);
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Why does It print out the last set of X\'s twice? I am doing basic Java so please try to explain
using the most basic codes.
Solution
Hi,
I have modified the code. it is working as expected now. Highlighted the code changes below.
Issue here is with you have written this statement twice System.out.println(x); which causes the
issue.
Program.java
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x=\"X\";
int amount;
System.out.println(\"Enter amount\");
amount=input.nextInt();
System.out.println(\"Amount is: \"+amount);
for(int i=1; i<=amount; i++)
{
System.out.println();
for(int j=1; j<=i; j++)
{
System.out.print(x);
}
}
}
}
Output:
Enter amount
10
Amount is: 10
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
XXXXXXXX
XXXXXXXXX
XXXXXXXXXX.
This document discusses how to take input from users in Java using the Scanner class. It provides examples of taking integer, double, character and string input. The Scanner class methods like nextInt(), nextDouble(), next() etc are used to read input. The document also contains sample code and explanations for taking input to calculate sum of two numbers, simple interest and reading a character.
Code:
import java.util.Random;
import java.util.Scanner;
public class Test{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String bin = \"1\";
int n;
System.out.print(\"Enter the number of binary digits : \");
n = input.nextInt();
for(int i = 0; i < n-1; i++){
bin += randomBin();
}
System.out.println(bin);
}
public static String randomBin() {
Random rg = new Random();
int n = rg.nextInt(2);
return Integer.toBinaryString(n);
}
}
Output:
Enter the number of binary digits : 5
10110
Solution
Code:
import java.util.Random;
import java.util.Scanner;
public class Test{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String bin = \"1\";
int n;
System.out.print(\"Enter the number of binary digits : \");
n = input.nextInt();
for(int i = 0; i < n-1; i++){
bin += randomBin();
}
System.out.println(bin);
}
public static String randomBin() {
Random rg = new Random();
int n = rg.nextInt(2);
return Integer.toBinaryString(n);
}
}
Output:
Enter the number of binary digits : 5
10110.
import java.util.Scanner;public class ArrayOperation { inp.pdfangelsfashion1
import java.util.Scanner;
public class ArrayOperation {
/* input method implementation */
public static double[] input() {
Scanner sc = new Scanner(System.in);
System.out.println(\"Please enter the size of array\");
int n = sc.nextInt();
double number[] = new double[n];
/* Inserting element to array */
for (int i = 0; i < n; i++) {
number[i] = sc.nextDouble();
}
/* printing array by calling print method */
print(number);
return number;
}
public static void print(double number[]) {
/* Printing array */
for (int i = 0; i < number.length; i++) {
System.out.print(number[i] + \" \");
}
System.out.println();
}
/* sqrtnumber method implemantation */
public static void sqrtNumber(double number[]) {
/* Printing sqrt of numbers */
System.out.println(\"Square root of Number of an array\");
for (int i = 0; i < number.length; i++) {
double num = Math.sqrt(number[i]);
System.out.println(num);
}
}
public static void main(String args[]) {
/* Calling initaize array */
double number[] = input();
/* calling sqrtnumber */
sqrtNumber(number);
}
}
/***********output*****************/
Please enter the size of array
5
5
6
7
8
14
5.0 6.0 7.0 8.0 14.0
Square root of Number of an array
2.23606797749979
2.449489742783178
2.6457513110645907
2.8284271247461903
3.7416573867739413
Solution
import java.util.Scanner;
public class ArrayOperation {
/* input method implementation */
public static double[] input() {
Scanner sc = new Scanner(System.in);
System.out.println(\"Please enter the size of array\");
int n = sc.nextInt();
double number[] = new double[n];
/* Inserting element to array */
for (int i = 0; i < n; i++) {
number[i] = sc.nextDouble();
}
/* printing array by calling print method */
print(number);
return number;
}
public static void print(double number[]) {
/* Printing array */
for (int i = 0; i < number.length; i++) {
System.out.print(number[i] + \" \");
}
System.out.println();
}
/* sqrtnumber method implemantation */
public static void sqrtNumber(double number[]) {
/* Printing sqrt of numbers */
System.out.println(\"Square root of Number of an array\");
for (int i = 0; i < number.length; i++) {
double num = Math.sqrt(number[i]);
System.out.println(num);
}
}
public static void main(String args[]) {
/* Calling initaize array */
double number[] = input();
/* calling sqrtnumber */
sqrtNumber(number);
}
}
/***********output*****************/
Please enter the size of array
5
5
6
7
8
14
5.0 6.0 7.0 8.0 14.0
Square root of Number of an array
2.23606797749979
2.449489742783178
2.6457513110645907
2.8284271247461903
3.7416573867739413.
The document contains code for 9 Java programming practical assignments. The first practical accepts coefficients for a quadratic equation, calculates the roots and outputs the results. The second accepts two matrices as input and calculates their addition. The third sorts an array of strings in ascending order. The fourth creates an Animal interface and classes that implement it to demonstrate polymorphism. The remaining practicals demonstrate inheritance, exceptions, GUI programming using Swing components, and the List interface.
The document contains the solutions to 64 programming problems in Java. It provides the code to write programs that can:
1) Display patterns like right angle triangles and pyramids with numbers.
2) Check if a number is negative, zero or positive.
3) Sort arrays and insert or find elements in arrays.
4) Perform operations like calculating averages and separating even/odd numbers in arrays.
3) Find pair sums and rotate/add matrices.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPRAHUL
This Dissertation explores the particular circumstances of Mirzapur, a region located in the
core of India. Mirzapur, with its varied terrains and abundant biodiversity, offers an optimal
environment for investigating the changes in vegetation cover dynamics. Our study utilizes
advanced technologies such as GIS (Geographic Information Systems) and Remote sensing to
analyze the transformations that have taken place over the course of a decade.
The complex relationship between human activities and the environment has been the focus
of extensive research and worry. As the global community grapples with swift urbanization,
population expansion, and economic progress, the effects on natural ecosystems are becoming
more evident. A crucial element of this impact is the alteration of vegetation cover, which plays a
significant role in maintaining the ecological equilibrium of our planet.Land serves as the foundation for all human activities and provides the necessary materials for
these activities. As the most crucial natural resource, its utilization by humans results in different
'Land uses,' which are determined by both human activities and the physical characteristics of the
land.
The utilization of land is impacted by human needs and environmental factors. In countries
like India, rapid population growth and the emphasis on extensive resource exploitation can lead
to significant land degradation, adversely affecting the region's land cover.
Therefore, human intervention has significantly influenced land use patterns over many
centuries, evolving its structure over time and space. In the present era, these changes have
accelerated due to factors such as agriculture and urbanization. Information regarding land use and
cover is essential for various planning and management tasks related to the Earth's surface,
providing crucial environmental data for scientific, resource management, policy purposes, and
diverse human activities.
Accurate understanding of land use and cover is imperative for the development planning
of any area. Consequently, a wide range of professionals, including earth system scientists, land
and water managers, and urban planners, are interested in obtaining data on land use and cover
changes, conversion trends, and other related patterns. The spatial dimensions of land use and
cover support policymakers and scientists in making well-informed decisions, as alterations in
these patterns indicate shifts in economic and social conditions. Monitoring such changes with the
help of Advanced technologies like Remote Sensing and Geographic Information Systems is
crucial for coordinated efforts across different administrative levels. Advanced technologies like
Remote Sensing and Geographic Information Systems
9
Changes in vegetation cover refer to variations in the distribution, composition, and overall
structure of plant communities across different temporal and spatial scales. These changes can
occur natural.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
2. import java.util.Scanner;
public class AreaOfSquare
{
public static void main(String args[])
{
int length, area;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length of the square ::");
length = sc.nextInt();
area = length* length;
System.out.println("Area of the square is ::"+area);
}
}
Area of a square
3. Output: Area of a square
Enter the length of the square :: 55
Area of the square is ::3025
4. Identify the number- Odd or Even
import java.util.Scanner;
class CheckEvenOdd
{
public static void main(String args[])
{
int num;
System.out.println("Enter an Integer number:");
Scanner input = new Scanner(System.in);
num = input.nextInt();
if ( num % 2 == 0 )
System.out.println("Entered number is even");
else
System.out.println("Entered number is odd");
} }
5. Output: odd or even
Output 1:
Enter an Integer number: 78
Entered number is even
Output 2:
Enter an Integer number: 77
Entered number is odd
6. class Descending
{
public static void main(String args[])
{
int i=10;
do
{
System.out.println(i);
i--;
}
while(i>1);
}
}
Print numbers in descending order.
8. class SumIntegers
{
public static void main(String args[])
{
int sum = 0;
for (int x = 1; x <= 20; x++)
{
sum = sum + x;
}
System.out.println("Sum: " + sum);
}
}
Sum of first 20 integers