Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- coded by newt
- only some of the codes are compatible with cmd; for educational purposes only
- all codes below (except /* codes) are original and thought of in the brightest way possible
- they are all examples, so feel free to modify them in any manner if possible
- */
- /* example of declaring multiple variables */
- int a,b,c;
- float marks;
- char name;
- /* example of initializing multiple variables */
- a=3, b=5;
- marks=45.5;
- name='y';
- /* example of declaring and initializing variables at the same time */
- int a=2, b=4;
- float marks=34.5
- double do=20.22d;
- /* accepting two numbers and printing their sum */
- import java.util.*;
- class total
- {
- public static void main(String[]args)
- {
- Scanner sc - new Scanner(System.in);
- int a,b,tot;
- System.out.print("\n Please enter the first number: ");
- a=sc.nextInt(); /* inputs statement in java & inputs a number in a */
- System.out.print("\n Please enter the second number: ");
- b=sc.nextInt();
- tot=a+b;
- System.out.println(" \ The sum is " +tot);
- }
- }
- /* IF statement syntax */
- if (condition)
- {
- True statements
- }
- else
- {
- False statement
- }
- /* to accept two numbers and print the largest of the two numbers */
- import java.util.*;
- class diff
- {
- public static void main(String[]args)
- {
- Scanner sc - new Scanner(System.in);
- int a,b;
- System.out.print("n\ Please enter the first number: ");
- a=sc.nextInt(); /* inputs statement in java & inputs a number in a */
- System.out.print("n\ Please enter the second number: ");
- b=sc.nextInt();
- if (a>b)
- {
- System.out.println("The first number is bigger");
- }
- else
- {
- System.out.println("The second number is bigger");
- }
- }
- }
- /* to print natural numbers from 1 to 5 */
- class natural
- {
- public static void main(String[]args)
- {
- int i=1;
- while(i<=5)
- {
- System.out.println("The value of i is " +i);
- i=i+1;
- }
- }
- }
- /* syntax when using DO, WHILE LOOP */
- do
- {
- block of statements
- }
- while(test condition)
- /* to print even numbers from 2 to 10 */
- class evennumber
- {
- public static void main(String[]args)
- {
- int i=2;
- System.out.println("The even numbers from 1 to 5 are:");
- while(i<=10)
- {
- System.out.println(i);
- i=i+2;
- }
- }
- }
- /* syntax when using FOR LOOP */
- for (start ; condition ; step value)
- /* to print numbers from 1 to 10 in reverse order */
- class reverse
- {
- public static void main(String[]args)
- {
- int=i;
- System.out.println("The numbers from 1 to 10 in reverse order are:");
- for(i=10;i>=1;i--)
- {
- System.out.println(i);
- }
- }
- }
- /*
- congratulations! you have finished newt's java example guide!
- if you read through everything and used some of it - GREAT!
- if you just scrolled to the end - LOSER!
- copyright 2014 newt drost
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement