The document is a 4 page sample code document containing examples of Java programming concepts. Page 1 contains code demonstrating if/else statements and printing output based on integer values. Page 2 imports a Scanner class and gets integer, float, and string user input. Page 3 briefly introduces arrays as a way to hold multiple values like columns in a spreadsheet. Page 4 indicates it will provide examples of arrays and loops.
Finding root of equation (numarical method)Rajan Thakkar
▪ The numerical methods provide a real solution to problems where f (x) = 0.
▪ Here we are not only programing these methods but also to analyze which method converges who faster than the other method.
▪ We measure the average time to solve each method (how much time conduct for solving by each method) and the iteration (In how many iterations the method converges.)
▪ Use dynamic input so that user can input its own choice of function
▪ We use the graph for new point so that if f(x)=0 than what is the value x we can easily find out by viewing the graph
▪ In That we also compare two different language which is faster c++ or python.
▪ We conclude that among all the Newton Raphson is efficient method.
▪ Note: calculation time is low in bisection method and give answer in too many iterations but depending upon system newton Raphson is take little bit more time but find the root in few iterations.
Finding root of equation (numarical method)Rajan Thakkar
▪ The numerical methods provide a real solution to problems where f (x) = 0.
▪ Here we are not only programing these methods but also to analyze which method converges who faster than the other method.
▪ We measure the average time to solve each method (how much time conduct for solving by each method) and the iteration (In how many iterations the method converges.)
▪ Use dynamic input so that user can input its own choice of function
▪ We use the graph for new point so that if f(x)=0 than what is the value x we can easily find out by viewing the graph
▪ In That we also compare two different language which is faster c++ or python.
▪ We conclude that among all the Newton Raphson is efficient method.
▪ Note: calculation time is low in bisection method and give answer in too many iterations but depending upon system newton Raphson is take little bit more time but find the root in few iterations.
"We Are All Treaty People" is a slide presentation by the London District Chiefs Council which provides a visual timeline of our history and illustration of our relationship with the Crown as represented by the Government of Canada.
This tutorial is made for people who want to type in Hindi in any program like MS Word, MS Excel, MS PowerPoint or want to chat / write emails in Hindi language without having any skills in Hindi typing. Microsoft's BhashaIndia software which provides tools for easy phonetic typing in various Indian languages including Hindi, Tamil, Kannada, Bengali, Punjabi etc. is an easy to use tool.
URLs are how we talk to the web and how we talk about the web. A user's first interaction with your site isn't viewing a page or reading your content, it's seeing your URL. This talk covers how we know that, what it means, and how to create good URLs.
View the full version of this slide deck at http://blog.rnf.me/ux-of-urls
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.
//Driver.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Driver
{
public static void printSequence (int num)
{
if(num > 0)
{
for (int i = 0; i <= num ;i++ )
{
System.out.print(i + \" \");
}
System.out.println();
}
else if(num < 0)
{
for (int i = 0; i >= num ;i-- )
{
System.out.print(i + \" \");
}
System.out.println();
}
}
public static int trianglarNum (int num)
{
int sum = 0;
if(num > 0)
{
for (int i = 1; i <= num ;i++ )
{
sum = sum + i;
}
return sum;
}
else
return -1;
}
public static void printArray(int list [])
{
for (int i = 0; i < list.length ;i++ )
{
System.out.print(list[i] + \" \");
}
System.out.println();
}
public static int range(int list [])
{
int max,min;
max = list[0];
min = list[0];
for (int i = 1; i < list.length ;i++ )
{
if(list[i] > max)
max = list[i];
if(list[i] < min)
min = list[i];
}
System.out.println(\"difference between the maximum and minimum values in the array: \"+
(max-min));
return (max-min);
}
public static void main(String[] args)
{
printSequence(10);
printSequence(-10);
System.out.println();
if(trianglarNum(10) > 0)
System.out.println(\"Sum: \"+ trianglarNum(10));
else
System.out.println(\"Negative input\ \");
if(trianglarNum(-10) > 0)
System.out.println(\"Sum: \"+ trianglarNum(-10));
else
System.out.println(\"Negative input\ \ \");
int array[] = {1,2,4,5,-4,7,8,11,5,7};
printArray(array);
System.out.println();
System.out.println(\"difference between the maximum and minimum values in the array: \"+
range(array));
}
}
/*
output:
0 1 2 3 4 5 6 7 8 9 10
0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Sum: 55
Negative input
1 2 4 5 -4 7 8 11 5 7
difference between the maximum and minimum values in the array: 15
difference between the maximum and minimum values in the array: 15
*/
Solution
//Driver.java
import java.util.Scanner;
import java.text.DecimalFormat;
public class Driver
{
public static void printSequence (int num)
{
if(num > 0)
{
for (int i = 0; i <= num ;i++ )
{
System.out.print(i + \" \");
}
System.out.println();
}
else if(num < 0)
{
for (int i = 0; i >= num ;i-- )
{
System.out.print(i + \" \");
}
System.out.println();
}
}
public static int trianglarNum (int num)
{
int sum = 0;
if(num > 0)
{
for (int i = 1; i <= num ;i++ )
{
sum = sum + i;
}
return sum;
}
else
return -1;
}
public static void printArray(int list [])
{
for (int i = 0; i < list.length ;i++ )
{
System.out.print(list[i] + \" \");
}
System.out.println();
}
public static int range(int list [])
{
int max,min;
max = list[0];
min = list[0];
for (int i = 1; i < list.length ;i++ )
{
if(list[i] > max)
max = list[i];
if(list[i] < min)
min = list[i];
}
System.out.println(\"difference between the maximum and minimum values in the array: \"+
(max-min));
return (max-min);
}
public static void main(String[] args)
{
printSequence(10);
printSequence(-10);
System.out.println();
if(trianglarNum(10) > 0)
System.out.println(\"Sum: \"+ trianglarNum(10));
else
System.out.println(\"Negative input\ \");
if(trianglarNum(-10) > 0)
System.out.println(\"Sum:.
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.
Have you ever wanted to add a new feature to your code but instead found yourself spending hours trying to understand the existing code? Or adding a new feature and then finding out you've broken something else, supposedly unrelated, that used to work?
These slides hold a few tips on how to write code that'll be easier to understand, nicer to read and more simple to maintain.
1. Page 1 of 4
Practice Programs
public class Test {
public static void main(String args[]){
int x = 30;
if( x == 10 ){
System.out.print("Value of X is 10");
}else if( x == 20 ){
System.out.print("Value of X is 20");
}else if( x == 30 ){
System.out.print("Value of X is 30");
}else{
System.out.print("This is else statement");
}
}
}
import java.util.Scanner;
class GetInputFromUser
{
public static void main(String args[])
{
int a;
float b;
String s;
Scanner in = new Scanner(System.in);
System.out.println("Enter a string");
s = in.nextLine();
System.out.println("You entered string "+s);
System.out.println("Enter an integer");
a = in.nextInt();
System.out.println("You entered integer "+a);
System.out.println("Enter a float");
b = in.nextFloat();
System.out.println("You entered float "+b);
}
}
2. Page 2 of 4
Switch statement
What is an Array?
So far, you have been working with variables that hold only one value. The integer
variables you have set up have held only one number, and the string variables just
one long string of text. An array is a way to hold more than one value at a time. It's
like a list of items. Think of an array as the columns in a spreadsheet. You can have
a spreadsheet with only one column, or lots of columns. The data held in a single-list
array might look like this: